2
0
Fork 0
forked from zynk/zynk

Some more security fixes.

This commit is contained in:
Johannes Findeisen 2026-07-16 03:43:00 +02:00
commit a6ee428f7b
2 changed files with 24 additions and 10 deletions

View file

@ -1,3 +1,10 @@
2026.07.16 – Security hardening.
- Fixed buffer overflow in ai_child_task: plen unsigned underflow when history entries exceed prefix buffer size, causing out-of-bounds writes via snprintf.
- Fixed IRC injection in handle_nick_change: validate new nick for CRLF and control characters before storing in op cache.
- Fixed control char leak in irc_msg: drop message on strdup failure instead of sending unsanitized input on the wire.
- Fixed CRLF/control char injection in -pass argument: reject passwords containing control characters at startup.
2026.07.15 – Numerous optimizations and fixes. 2026.07.15 – Numerous optimizations and fixes.
- Fixed DB/TLS resource cleanup on partial startup failures and normal shutdown. - Fixed DB/TLS resource cleanup on partial startup failures and normal shutdown.

21
zynk.c
View file

@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...);
/* ---- constants ---- */ /* ---- constants ---- */
#define VERSION "0.32.1" #define VERSION "0.32.2"
#define DEFAULT_SERVER "irc.libera.chat" #define DEFAULT_SERVER "irc.libera.chat"
#define OPENCODE_BIN "/usr/bin/opencode" #define OPENCODE_BIN "/usr/bin/opencode"
#define CLR_RESET "\033[0m" #define CLR_RESET "\033[0m"
@ -852,11 +852,18 @@ static void ai_child_task(Session *s, long long id, const char *agent) {
"Just answer directly."); "Just answer directly.");
} }
if (have_history) { if (have_history) {
plen += snprintf(prefix + plen, sizeof prefix - plen, int space = (int)sizeof prefix - plen;
if (space > 0)
plen += snprintf(prefix + plen, space,
" My recent answers for context (only use if absolutely necessary): "); " My recent answers for context (only use if absolutely necessary): ");
if (plen >= (int)sizeof prefix) plen = (int)sizeof prefix - 1;
for (int i = 0; i < MAX_HISTORY; i++) { for (int i = 0; i < MAX_HISTORY; i++) {
if (history[i]) space = (int)sizeof prefix - plen;
plen += snprintf(prefix + plen, sizeof prefix - plen, "[%s] ", history[i]); if (space <= 0) break;
if (history[i]) {
plen += snprintf(prefix + plen, space, "[%s] ", history[i]);
if (plen >= (int)sizeof prefix) plen = (int)sizeof prefix - 1;
}
} }
} }
for (int i = 0; i < MAX_HISTORY; i++) free(history[i]); for (int i = 0; i < MAX_HISTORY; i++) free(history[i]);
@ -1029,11 +1036,10 @@ static void irc_msg(Session *s, const char *t, const char *txt) {
} }
if (need_clean) { if (need_clean) {
clean = strdup(send_txt); clean = strdup(send_txt);
if (clean) { if (!clean) return;
for (char *p = clean; *p; p++) if ((unsigned char)*p < 0x20 || (unsigned char)*p == 0x7f) *p = ' '; for (char *p = clean; *p; p++) if ((unsigned char)*p < 0x20 || (unsigned char)*p == 0x7f) *p = ' ';
send_txt = clean; send_txt = clean;
} }
}
if (tb[0]) net_send(s, "PRIVMSG %s :%s\r\n", tb, send_txt); if (tb[0]) net_send(s, "PRIVMSG %s :%s\r\n", tb, send_txt);
free(clean); free(clean);
} }
@ -1421,6 +1427,7 @@ static void handle_nick_change(Session *s, const char *prefix, const char *param
memcpy(src_nick, prefix, nlen); src_nick[nlen] = 0; memcpy(src_nick, prefix, nlen); src_nick[nlen] = 0;
const char *newnick = params; const char *newnick = params;
if (*newnick == ':') newnick++; if (*newnick == ':') newnick++;
if (!*newnick || has_crlf(newnick) || has_ctl(newnick)) return;
chan_rename_op(src_nick, newnick); chan_rename_op(src_nick, newnick);
if (strcasecmp(src_nick, s->nick) == 0) { if (strcasecmp(src_nick, s->nick) == 0) {
strncpy(s->nick, newnick, sizeof s->nick - 1); strncpy(s->nick, newnick, sizeof s->nick - 1);
@ -1655,7 +1662,7 @@ int main(int argc, char **argv) {
fprintf(stderr, CLR_RED "Invalid nick" CLR_RESET "\n"); fprintf(stderr, CLR_RED "Invalid nick" CLR_RESET "\n");
return 1; return 1;
} }
if (has_crlf(passbuf) || has_crlf(joinbuf)) { if (has_crlf(passbuf) || has_crlf(joinbuf) || has_ctl(passbuf)) {
fprintf(stderr, CLR_RED "Invalid IRC argument" CLR_RESET "\n"); fprintf(stderr, CLR_RED "Invalid IRC argument" CLR_RESET "\n");
return 1; return 1;
} }