fix: null pointer dereference guards (CWE-476)
All checks were successful
CI Code / Check spelling (pull_request) Successful in 17s
CI Code / Check coding style (pull_request) Successful in 32s
CI Code / Code Coverage (pull_request) Successful in 2m44s
CI Code / Linux (debian) (pull_request) Successful in 4m43s
CI Code / Linux (ubuntu) (pull_request) Successful in 4m58s
CI Code / Linux (arch) (pull_request) Successful in 5m49s

- cmd_funcs.c: check strtok() return before use in cmd_process_input
- cmd_funcs.c: check fdopen() return before use in cmd_sendfile
- omemo.c: init fingerprint_len=0 and check _omemo_fingerprint_decode()
  return in omemo_is_trusted_identity (CWE-457/CWE-690)
- omemo.c: early NULL return in _omemo_fingerprint_decode() for NULL input

Found via GCC -fanalyzer. Not covered by upstream.
This commit is contained in:
2026-04-17 16:22:56 +03:00
committed by jabber.developer2
parent 06b80bc89a
commit 0ad7327fea
2 changed files with 14 additions and 1 deletions

View File

@@ -211,6 +211,9 @@ cmd_process_input(ProfWin* window, char* inp)
if (inp[0] == '/') {
auto_char char* inp_cpy = strdup(inp);
char* command = strtok(inp_cpy, " ");
if (!command) {
return TRUE;
}
char* question_mark = strchr(command, '?');
if (question_mark) {
*question_mark = '\0';
@@ -4964,6 +4967,10 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
}
FILE* fh = fdopen(fd, "rb");
if (!fh) {
cons_show_error("Failed to open file for reading.");
goto out;
}
if (omemo_enabled) {
#ifdef HAVE_OMEMO

View File

@@ -1089,8 +1089,11 @@ omemo_is_trusted_identity(const char* const jid, const char* const fingerprint)
.device_id = GPOINTER_TO_INT(device_id),
};
size_t fingerprint_len;
size_t fingerprint_len = 0;
unsigned char* fingerprint_raw = _omemo_fingerprint_decode(fingerprint, &fingerprint_len);
if (!fingerprint_raw) {
return FALSE;
}
unsigned char djb_type[] = { '\x05' };
signal_buffer* buffer = signal_buffer_create(djb_type, 1);
buffer = signal_buffer_append(buffer, fingerprint_raw, fingerprint_len);
@@ -1149,6 +1152,9 @@ _omemo_fingerprint(ec_public_key* identity, gboolean formatted)
static unsigned char*
_omemo_fingerprint_decode(const char* const fingerprint, size_t* len)
{
if (!fingerprint) {
return NULL;
}
unsigned char* output = malloc(strlen(fingerprint) / 2 + 1);
int i;