From 3d2a82ad4aebf2e513d7cbaa197d1e73f6129299 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 26 Feb 2026 19:34:04 +0100 Subject: [PATCH] cleanup: Fix potential NULL dereference in cmd_omemo_(un)trust Replace malloc() with g_malloc() to handle allocation failure and ensure enough memory is allocated for the null terminator. --- src/command/cmd_funcs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index c4864414..c0a89827 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8714,8 +8714,8 @@ cmd_omemo_trust(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* fingerprint; - char* barejid; + gchar* fingerprint; + gchar* barejid; /* Contact not provided */ if (!args[2]) { @@ -8731,7 +8731,7 @@ cmd_omemo_trust(ProfWin* window, const char* const command, gchar** args) barejid = chatwin->barejid; } else { fingerprint = args[2]; - char* contact = args[1]; + gchar* contact = args[1]; barejid = roster_barejid_from_name(contact); if (barejid == NULL) { barejid = contact; @@ -8740,7 +8740,7 @@ cmd_omemo_trust(ProfWin* window, const char* const command, gchar** args) omemo_trust(barejid, fingerprint); - auto_char char* unformatted_fingerprint = malloc(strlen(fingerprint)); + auto_gchar gchar* unformatted_fingerprint = g_malloc(strlen(fingerprint) + 1); int i; int j; for (i = 0, j = 0; fingerprint[i] != '\0'; i++) { @@ -8781,8 +8781,8 @@ cmd_omemo_untrust(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* fingerprint; - char* barejid; + gchar* fingerprint; + gchar* barejid; /* Contact not provided */ if (!args[2]) { @@ -8807,7 +8807,7 @@ cmd_omemo_untrust(ProfWin* window, const char* const command, gchar** args) omemo_untrust(barejid, fingerprint); - auto_char char* unformatted_fingerprint = malloc(strlen(fingerprint)); + auto_gchar gchar* unformatted_fingerprint = g_malloc(strlen(fingerprint) + 1); int i, j; for (i = 0, j = 0; fingerprint[i] != '\0'; i++) { if (!g_ascii_isxdigit(fingerprint[i])) {