fix: null pointer dereference guards (CWE-476)
Some checks failed
CI Code / Code Coverage (pull_request) Failing after 10m45s
CI Code / Check spelling (pull_request) Failing after 11m2s
CI Code / Check coding style (pull_request) Failing after 11m21s
CI Code / Linux (ubuntu) (pull_request) Failing after 11m36s
CI Code / Linux (debian) (pull_request) Failing after 11m56s
CI Code / Linux (arch) (pull_request) Failing after 12m22s

- 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
parent 0722dc9e36
commit 43aeaf6e3b
2 changed files with 14 additions and 1 deletions

View File

@@ -210,6 +210,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';
@@ -4963,6 +4966,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;