From 41c0a5a9c6d5d403445ad9bac18823bae9c49b10 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Tue, 6 Jan 2009 15:58:18 +0100 Subject: [PATCH 1/4] Fix bip_notify usage These may lead to crash if you call in your conf networks or other names with %s or other fancy format strings. --- src/bip.c | 18 +++++++++--------- src/irc.c | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bip.c b/src/bip.c index 1eed76e..050004b 100644 --- a/src/bip.c +++ b/src/bip.c @@ -1379,7 +1379,7 @@ void adm_print_connection(struct link_client *ic, struct link *lnk, noroom: /* that means the line is larger that RET_STR_LEN. We're not likely to even read such a long line */ buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); // TODO: on_connect_send @@ -1396,13 +1396,13 @@ noroom: /* that means the line is larger that RET_STR_LEN. We're not likely to (ch->backlog ? "" : "`")); if (t_written > LINE_SIZE_LIM) { buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); t_written = 0; } } noroomchan: buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); t_written = snprintf(buf, RET_STR_LEN, " Status: "); if (t_written >= RET_STR_LEN) @@ -1462,7 +1462,7 @@ noroomchan: } noroomstatus: buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); } void adm_list_all_links(struct link_client *ic) @@ -1521,7 +1521,7 @@ void adm_info_user(struct link_client *ic, const char *name) noroom: buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); t_written = 0; #ifdef HAVE_LIBSSL @@ -1590,13 +1590,13 @@ void adm_list_users(struct link_client *ic) goto noroom; if (t_written > LINE_SIZE_LIM) { buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); t_written = 0; } } noroom: buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); } bip_notify(ic, "-- End of User list"); } @@ -1640,13 +1640,13 @@ void adm_list_networks(struct link_client *ic) goto noroom; if (t_written > LINE_SIZE_LIM) { buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); t_written = 0; } } noroom: buf[RET_STR_LEN] = 0; - bip_notify(ic, buf); + bip_notify(ic, "%s", buf); } bip_notify(ic, "-- End of Network list"); } diff --git a/src/irc.c b/src/irc.c index 1480e3f..870acbf 100644 --- a/src/irc.c +++ b/src/irc.c @@ -2469,7 +2469,7 @@ void irc_main(bip_t *bip) char *l; while ((l = list_remove_first(&bip->errors))) - bip_notify(bip->reloading_client, l); + bip_notify(bip->reloading_client, "%s", l); bip->reloading_client = NULL; } From eb57d9683d95ea49868f984ad2c2cd93e85fc351 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Tue, 6 Jan 2009 16:28:06 +0100 Subject: [PATCH 2/4] Drop some unused variable. --- src/bip.c | 1 - src/log.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/bip.c b/src/bip.c index 050004b..24cd7f4 100644 --- a/src/bip.c +++ b/src/bip.c @@ -1522,7 +1522,6 @@ void adm_info_user(struct link_client *ic, const char *name) noroom: buf[RET_STR_LEN] = 0; bip_notify(ic, "%s", buf); - t_written = 0; #ifdef HAVE_LIBSSL bip_notify(ic, "SSL check mode '%s', stored into '%s'", diff --git a/src/log.c b/src/log.c index 25d5dc9..14540ee 100644 --- a/src/log.c +++ b/src/log.c @@ -130,13 +130,11 @@ void replace_var(char *str, char *var, char *value, unsigned int max) char *log_build_filename(log_t *logdata, const char *destination) { char *logfile, year[5], day[3], month[3], *tmp, *logdir; - int log_format_len; struct tm *now; time_t s; char *dest = bip_strdup(destination); strtolower(dest); - log_format_len = strlen(conf_log_format); logfile = (char *)bip_malloc(MAX_PATH_LEN + 1); time(&s); From a57e76f883c8d7f138fb61eb2c8edc66413c7012 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Tue, 6 Jan 2009 16:34:17 +0100 Subject: [PATCH 3/4] add fclose on pid file --- src/bip.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bip.c b/src/bip.c index 24cd7f4..44b7770 100644 --- a/src/bip.c +++ b/src/bip.c @@ -228,6 +228,7 @@ pid_is_there: if (c != 1 || p == 0) { mylog(LOG_INFO, "pid file found but invalid " "data inside. Continuing...\n"); + fclose(f); if (unlink(conf_pid_file)) { fatal("Cannot delete pid file '%s', " "check permissions.\n", From d2f7840ced065d644ba626413f5e53900efb39ef Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Thu, 8 Jan 2009 11:01:47 +0100 Subject: [PATCH 4/4] [BUG] Fix fatal on some nick change When a nick changes to one for which we already have a logstore allocated. We try to overwrite a hash entry that is already existing leading to a fatal. This pach cleans things up before rename the logstore. --- src/log.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/log.c b/src/log.c index 14540ee..4cc543e 100644 --- a/src/log.c +++ b/src/log.c @@ -28,6 +28,7 @@ static int _log_write(log_t *logdata, logstore_t *lf, const char *d, const char *str); void logfile_free(logfile_t *lf); static char *_log_wrap(const char *dest, const char *line); +static void log_drop(log_t *log, const char *storename); #define BOLD_CHAR 0x02 #define LAMESTRING "!bip@bip.bip.bip PRIVMSG " @@ -457,8 +458,11 @@ void log_nick(log_t *logdata, const char *ircmask, const char *channel, { char *oldnick = nick_from_ircmask(ircmask); - if (hash_includes(&logdata->logfgs, oldnick)) + if (hash_includes(&logdata->logfgs, oldnick)) { + if (hash_includes(&logdata->logfgs, newnick)) + log_drop(logdata, newnick); hash_rename_key(&logdata->logfgs, oldnick, newnick); + } free(oldnick); snprintf(logdata->buffer, LOGLINE_MAXLEN, @@ -677,6 +681,27 @@ void log_client_disconnected(log_t *logdata) mylog(LOG_DEBUG, "A client disconnected"); } +void log_store_free(logstore_t *store) +{ + logfile_t *lf; + + log_reset(store); + if ((lf = list_remove_first(&store->file_group))) + logfile_free(lf); + free(store->name); + if (store->memlog) + list_free(store->memlog); + free(store); +} + +static void log_drop(log_t *log, const char *storename) +{ + logstore_t *store; + + store = hash_remove(&log->logfgs, storename); + log_store_free(store); +} + void log_reinit_all(log_t *logdata) { logstore_t *store; @@ -1243,7 +1268,6 @@ void log_free(log_t *log) { hash_iterator_t it; logstore_t *store; - logfile_t *lf; list_remove(log_all_logs, log); @@ -1253,8 +1277,7 @@ void log_free(log_t *log) for (hash_it_init(&log->logfgs, &it); (store = hash_it_item(&it)); hash_it_next(&it)) { log_reset(store); - if ((lf = list_remove_first(&store->file_group))) - logfile_free(lf); + log_store_free(store); } hash_clean(&log->logfgs); free(log);