fix: CWE-134 format string vulnerability audit
All checks were successful
CI Code / Check spelling (pull_request) Successful in 21s
CI Code / Check coding style (pull_request) Successful in 38s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m25s
CI Code / Linux (debian) (pull_request) Successful in 9m11s
CI Code / Code Coverage (pull_request) Successful in 9m13s
CI Code / Linux (arch) (pull_request) Successful in 11m27s

Security:
- Fix CWE-134 in iq.c: user-controlled string passed as format arg

Annotations:
- Add G_GNUC_PRINTF to variadic functions in ui.h and log.h

Compiler flags (configure.ac):
- Add -Wformat -Wformat-nonliteral -Wno-format-zero-length

Format mismatch fixes:
- chatwin.c: Jid* instead of char* for %s
- connection.c: %x -> %lx for long flags
- cmd_funcs.c: %d -> %zu for MB_CUR_MAX/MB_LEN_MAX (size_t)
- cmd_funcs.c: cast gpointer to (char*) for %s
- cmd_defs.c: %d -> %u for g_list_length() (guint)
- iq.c: from_jid->barejid -> from_jid->fulljid
- console.c, mucwin.c, privwin.c, account.c, omemo.c, presence.c:
  gpointer -> (char*) casts for %s

Bug fixes:
- api.c: broken log_warning() calls with extra format arg
- cmd_funcs.c: remove unused arg from cons_show()

Tooling:
- Expand check-cwe134.sh detection patterns
This commit is contained in:
2026-03-03 14:53:18 +03:00
parent 31538580fb
commit 92953099e1
16 changed files with 258 additions and 72 deletions

View File

@@ -2271,7 +2271,7 @@ cmd_group(ProfWin* window, const char* const command, gchar** args)
if (curr) {
cons_show("Groups:");
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_list_next(curr);
}
@@ -3109,7 +3109,7 @@ cmd_blocked(ProfWin* window, const char* const command, gchar** args)
if (curr) {
cons_show("Blocked users:");
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_list_next(curr);
}
} else {
@@ -5190,7 +5190,7 @@ cmd_charset(ProfWin* window, const char* const command, gchar** args)
if (codeset) {
cons_show(" CODESET: %s", codeset);
}
cons_show(" MB_CUR_MAX: %d", MB_CUR_MAX);
cons_show(" MB_CUR_MAX: %zu", MB_CUR_MAX);
cons_show(" MB_LEN_MAX: %d", MB_LEN_MAX);
return TRUE;
@@ -5624,7 +5624,7 @@ cmd_notify(ProfWin* window, const char* const command, gchar** args)
cons_show("No room notification triggers");
}
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_list_next(curr);
}
g_list_free_full(triggers, free);
@@ -6299,7 +6299,7 @@ cmd_reconnect(ProfWin* window, const char* const command, gchar** args)
} else if (strtoi_range(value, &intval, 0, INT_MAX, &err_msg)) {
prefs_set_reconnect(intval);
if (intval == 0) {
cons_show("Reconnect disabled.", intval);
cons_show("Reconnect disabled.");
} else {
cons_show("Reconnect interval set to %d seconds.", intval);
}
@@ -6858,7 +6858,7 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
cons_show("");
cons_show("Installed and loaded plugins (%u):", g_slist_length(curr));
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_slist_next(curr);
}
}
@@ -6867,7 +6867,7 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
cons_show("");
cons_show("Failed installs (%u):", g_slist_length(curr));
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_slist_next(curr);
}
}
@@ -6969,7 +6969,7 @@ cmd_plugins_load(ProfWin* window, const char* const command, gchar** args)
cons_show("Loaded plugins:");
GSList* curr = loaded;
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_slist_next(curr);
}
g_slist_free_full(loaded, g_free);
@@ -7101,7 +7101,7 @@ cmd_plugins(ProfWin* window, const char* const command, gchar** args)
GSList* curr = unloaded_plugins;
cons_show("The following plugins already installed and can be loaded:");
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_slist_next(curr);
}
g_slist_free_full(unloaded_plugins, g_free);
@@ -7111,7 +7111,7 @@ cmd_plugins(ProfWin* window, const char* const command, gchar** args)
GList* curr = plugins;
cons_show("Loaded plugins:");
while (curr) {
cons_show(" %s", curr->data);
cons_show(" %s", (char*)curr->data);
curr = g_list_next(curr);
}
g_list_free(plugins);