fix: CWE-134 format string audit and compiler hardening
All checks were successful
CI Code / Check spelling (push) Successful in 20s
CI Code / Check coding style (push) Successful in 36s
CI Code / Code Coverage (push) Successful in 5m38s
CI Code / Linux (ubuntu) (push) Successful in 7m1s
CI Code / Linux (debian) (push) Successful in 7m5s
CI Code / Linux (arch) (push) Successful in 7m19s
All checks were successful
CI Code / Check spelling (push) Successful in 20s
CI Code / Check coding style (push) Successful in 36s
CI Code / Code Coverage (push) Successful in 5m38s
CI Code / Linux (ubuntu) (push) Successful in 7m1s
CI Code / Linux (debian) (push) Successful in 7m5s
CI Code / Linux (arch) (push) Successful in 7m19s
Security: Fix CWE-134 in iq.c: user-controlled string passed as format argument Add G_GNUC_PRINTF annotations to all variadic printf-like wrappers in ui.h, log.h and http_common.h Compiler flags (configure.ac): Replace basic -Wformat/-Wformat-nonliteral with -Wformat=2 Add -Wextra, -Wnull-dereference, -Wpointer-arith, -Wimplicit-function-declaration, -Wundef, -Wfloat-equal, -Wredundant-decls, -Walloc-zero Add -fstack-protector-strong, -fno-common, -D_FORTIFY_SOURCE=2 Add GCC-specific flags via AC_COMPILE_IFELSE: -Wlogical-op, -Wduplicated-cond, -Wduplicated-branches, -Wstringop-overflow, -Warray-bounds=2 Suppress noisy -Wextra sub-warnings: -Wno-unused-parameter, -Wno-missing-field-initializers, -Wno-sign-compare, -Wno-cast-function-type Remove AM_CFLAGS/CFLAGS duplication Bug fixes found by new warnings: chatlog.c: non-MUCPM redact path passed resourcepart instead of NULL rosterwin.c: merge duplicated if/else branches into single condition omemo.c: redundant else-if in omemo_automatic_start; remove unnecessary scope block and goto, use early return console.c: pointer compared to integer 0 instead of NULL stanza.c: increase pri_str/idle_str buffers from 10 to 12 bytes (INT_MIN = -2147483648 needs 12 bytes including NUL) vcard.c: NULL guard for filename before g_file_set_contents api.c: broken log_warning() calls with extra format argument Format mismatch fixes: chatwin.c: Jid* → char* for %s connection.c: %x → %lx for long flags cmd_funcs.c: %d → %zu for size_t; cast gpointer to char* for %s cmd_defs.c: %d → %u for g_list_length() return (guint) iq.c: barejid → fulljid for from_jid console.c, mucwin.c, privwin.c, account.c, omemo.c, presence.c: gpointer → (char*) casts for %s Const-correctness and cleanup: database.c: const for type, query, sort variables form.c/xmpp.h: const for form_set_value parameter files.c: refactor to early return, eliminating NULL logfile path muc.c/muc.h: remove meaningless top-level const on return type common.c: const for URL string literal Remove stale declarations: cons_show_desktop_prefs (ui.h), connection_set_priority (connection.h), omemo_devicelist_configure_and_request (omemo.h) test_common.c: add currb NULL check to silence -Wnull-dereference Tooling (check-cwe134.sh): Reduce from 5 checks to 2 (checks 1-3 redundant with -Wformat=2) Check 1: verify known wrappers have G_GNUC_PRINTF attribute Check 2: auto-detect unannotated variadic printf-like functions Match both const char* and const gchar* in variadic patterns Author: jabber.developer2 <jabber.developer2@jabber.space>
This commit is contained in:
@@ -303,7 +303,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
assert(chatwin != NULL);
|
||||
|
||||
if (message->plain == NULL) {
|
||||
log_error("chatwin_incoming_msg: Message with no plain field from: %s", message->from_jid);
|
||||
log_error("chatwin_incoming_msg: Message with no plain field from: %s", message->from_jid->fulljid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -470,10 +470,10 @@ cons_show_wins(gboolean unread)
|
||||
|
||||
GSList* curr = window_strings;
|
||||
while (curr) {
|
||||
if (g_strstr_len(curr->data, strlen(curr->data), " unread") > 0) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", curr->data);
|
||||
if (g_strstr_len((char*)curr->data, strlen((char*)curr->data), " unread") != NULL) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", (char*)curr->data);
|
||||
} else {
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", curr->data);
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", (char*)curr->data);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@@ -491,10 +491,10 @@ cons_show_wins_attention()
|
||||
|
||||
GSList* curr = window_strings;
|
||||
while (curr) {
|
||||
if (g_strstr_len(curr->data, strlen(curr->data), " unread") > 0) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", curr->data);
|
||||
if (g_strstr_len((char*)curr->data, strlen((char*)curr->data), " unread") != NULL) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", (char*)curr->data);
|
||||
} else {
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", curr->data);
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", (char*)curr->data);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@@ -512,7 +512,7 @@ cons_show_room_invites(GList* invites)
|
||||
} else {
|
||||
cons_show("Chat room invites, use /join or /decline commands:");
|
||||
while (invites) {
|
||||
cons_show(" %s", invites->data);
|
||||
cons_show(" %s", (char*)invites->data);
|
||||
invites = g_list_next(invites);
|
||||
}
|
||||
}
|
||||
@@ -591,7 +591,7 @@ cons_show_caps(const char* const fulljid, resource_presence_t presence)
|
||||
win_println(console, THEME_DEFAULT, "-", "Features:");
|
||||
GSList* feature = caps->features;
|
||||
while (feature) {
|
||||
win_println(console, THEME_DEFAULT, "-", " %s", feature->data);
|
||||
win_println(console, THEME_DEFAULT, "-", " %s", (char*)feature->data);
|
||||
feature = g_slist_next(feature);
|
||||
}
|
||||
}
|
||||
@@ -611,10 +611,10 @@ cons_show_received_subs(void)
|
||||
if (received == NULL) {
|
||||
cons_show("No outstanding subscription requests.");
|
||||
} else {
|
||||
cons_show("Outstanding subscription requests from:",
|
||||
cons_show("Outstanding subscription requests from (%d):",
|
||||
g_list_length(received));
|
||||
while (received) {
|
||||
cons_show(" %s", received->data);
|
||||
cons_show(" %s", (char*)received->data);
|
||||
received = g_list_next(received);
|
||||
}
|
||||
g_list_free_full(received, g_free);
|
||||
@@ -782,7 +782,7 @@ cons_show_disco_info(const char* jid, GSList* identities, GSList* features)
|
||||
cons_show(" Features:");
|
||||
}
|
||||
while (features) {
|
||||
cons_show(" %s", features->data);
|
||||
cons_show(" %s", (char*)features->data);
|
||||
features = g_slist_next(features);
|
||||
}
|
||||
|
||||
@@ -2297,7 +2297,7 @@ cons_show_themes(GSList* themes)
|
||||
} else {
|
||||
cons_show("Available themes:");
|
||||
while (themes) {
|
||||
cons_show("%s", themes->data);
|
||||
cons_show("%s", (char*)themes->data);
|
||||
themes = g_slist_next(themes);
|
||||
}
|
||||
}
|
||||
@@ -2315,7 +2315,7 @@ cons_show_scripts(GSList* scripts)
|
||||
} else {
|
||||
cons_show("Scripts:");
|
||||
while (scripts) {
|
||||
cons_show("%s", scripts->data);
|
||||
cons_show("%s", (char*)scripts->data);
|
||||
scripts = g_slist_next(scripts);
|
||||
}
|
||||
}
|
||||
@@ -2333,7 +2333,7 @@ cons_show_script(const char* const script, GSList* commands)
|
||||
} else {
|
||||
cons_show("%s:", script);
|
||||
while (commands) {
|
||||
cons_show(" %s", commands->data);
|
||||
cons_show(" %s", (char*)commands->data);
|
||||
commands = g_slist_next(commands);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ mucwin_room_disco_info(ProfMucWin* mucwin, GSList* identities, GSList* features)
|
||||
win_println(window, THEME_DEFAULT, "!", "Features:");
|
||||
}
|
||||
while (features) {
|
||||
win_println(window, THEME_DEFAULT, "!", " %s", features->data);
|
||||
win_println(window, THEME_DEFAULT, "!", " %s", (char*)features->data);
|
||||
features = g_slist_next(features);
|
||||
}
|
||||
win_println(window, THEME_DEFAULT, "-", "");
|
||||
@@ -534,7 +534,7 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList
|
||||
int flags = 0;
|
||||
|
||||
if (message->plain == NULL) {
|
||||
log_error("mucwin_incoming_msg: Message with no plain field from: %s", message->from_jid);
|
||||
log_error("mucwin_incoming_msg: Message with no plain field from: %s", message->from_jid->fulljid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
assert(privatewin != NULL);
|
||||
|
||||
if (message->plain == NULL) {
|
||||
log_error("privwin_incoming_msg: Message with no plain field from: %s", message->from_jid);
|
||||
log_error("privwin_incoming_msg: Message with no plain field from: %s", message->from_jid->fulljid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -981,9 +981,7 @@ _rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins)
|
||||
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
|
||||
if (g_strcmp0(countpref, "items") == 0) {
|
||||
int itemcount = g_list_length(wins);
|
||||
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
} else {
|
||||
if (itemcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
}
|
||||
} else if (g_strcmp0(countpref, "unread") == 0) {
|
||||
@@ -994,9 +992,7 @@ _rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins)
|
||||
unreadcount += chatwin->unread;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
} else if (unreadcount > 0) {
|
||||
if (unreadcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
}
|
||||
}
|
||||
@@ -1026,9 +1022,7 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL
|
||||
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
|
||||
if (g_strcmp0(countpref, "items") == 0) {
|
||||
int itemcount = g_slist_length(contacts);
|
||||
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
} else {
|
||||
if (itemcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
}
|
||||
} else if (g_strcmp0(countpref, "unread") == 0) {
|
||||
@@ -1043,9 +1037,7 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
} else if (unreadcount > 0) {
|
||||
if (unreadcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
}
|
||||
}
|
||||
@@ -1136,9 +1128,7 @@ _rosterwin_private_header(ProfLayoutSplit* layout, GList* privs)
|
||||
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
|
||||
if (g_strcmp0(countpref, "items") == 0) {
|
||||
int itemcount = g_list_length(privs);
|
||||
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(title_str, " (%d)", itemcount);
|
||||
} else if (itemcount > 0) {
|
||||
if (itemcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(title_str, " (%d)", itemcount);
|
||||
}
|
||||
} else if (g_strcmp0(countpref, "unread") == 0) {
|
||||
@@ -1149,9 +1139,7 @@ _rosterwin_private_header(ProfLayoutSplit* layout, GList* privs)
|
||||
unreadcount += privwin->unread;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(title_str, " (%d)", unreadcount);
|
||||
} else if (unreadcount > 0) {
|
||||
if (unreadcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(title_str, " (%d)", unreadcount);
|
||||
}
|
||||
}
|
||||
|
||||
14
src/ui/ui.h
14
src/ui/ui.h
@@ -244,7 +244,9 @@ char* inp_readline(void);
|
||||
void inp_nonblocking(gboolean reset);
|
||||
|
||||
// Console window
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void cons_show(const char* const msg, ...);
|
||||
G_GNUC_PRINTF(2, 3)
|
||||
void cons_show_padded(int pad, const char* const msg, ...);
|
||||
void cons_about(void);
|
||||
void cons_help(void);
|
||||
@@ -263,7 +265,9 @@ void cons_show_pgp_prefs(void);
|
||||
void cons_show_omemo_prefs(void);
|
||||
void cons_show_ox_prefs(void);
|
||||
void cons_show_account(ProfAccount* account);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void cons_debug(const char* const msg, ...);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void cons_show_error(const char* const cmd, ...);
|
||||
void cons_show_contacts(GSList* list);
|
||||
void cons_show_roster(GSList* list);
|
||||
@@ -318,7 +322,6 @@ void cons_wrap_setting(void);
|
||||
void cons_time_setting(void);
|
||||
void cons_wintitle_setting(void);
|
||||
void cons_notify_setting(void);
|
||||
void cons_show_desktop_prefs(void);
|
||||
void cons_states_setting(void);
|
||||
void cons_outtype_setting(void);
|
||||
void cons_intype_setting(void);
|
||||
@@ -393,16 +396,24 @@ void win_show_subwin(ProfWin* window);
|
||||
void win_refresh_without_subwin(ProfWin* window);
|
||||
void win_refresh_with_subwin(ProfWin* window);
|
||||
|
||||
G_GNUC_PRINTF(4, 5)
|
||||
void win_print(ProfWin* window, theme_item_t theme_item, const char* show_char, const char* const message, ...);
|
||||
G_GNUC_PRINTF(4, 5)
|
||||
void win_println(ProfWin* window, theme_item_t theme_item, const char* show_char, const char* const message, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_println_indent(ProfWin* window, int pad, const char* const message, ...);
|
||||
|
||||
G_GNUC_PRINTF(4, 0)
|
||||
void win_println_va(ProfWin* window, theme_item_t theme_item, const char* show_char, const char* const message, va_list arg);
|
||||
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_append(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_appendln(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_append_highlight(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_appendln_highlight(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
|
||||
gchar* win_get_title(ProfWin* window);
|
||||
@@ -416,6 +427,7 @@ void win_clear(ProfWin* window);
|
||||
char* win_get_tab_identifier(ProfWin* window);
|
||||
gchar* win_to_string(ProfWin* window);
|
||||
void win_command_list_error(ProfWin* window, const char* const error);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_command_exec_error(ProfWin* window, const char* const command, const char* const error, ...);
|
||||
void win_handle_command_list(ProfWin* window, GSList* cmds);
|
||||
void win_handle_command_exec_status(ProfWin* window, const char* const type, const char* const value);
|
||||
|
||||
Reference in New Issue
Block a user