From 2a5e7b6f7bea243117d671ec4812f63b46a23a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gomez?= Date: Sun, 9 Jan 2022 21:20:49 +0100 Subject: [PATCH] sanitize: add trivial casts to types and add missing default cases --- src/bip.c | 14 +++++--- src/bip_main.c | 4 +-- src/connection.c | 26 ++++++++++----- src/irc.c | 35 ++++++++++---------- src/irc.h | 3 +- src/line.h | 5 +-- src/log.c | 86 +++++++++++++++++++++++++----------------------- src/md5.c | 11 ++++--- src/util.c | 6 ++-- 9 files changed, 102 insertions(+), 88 deletions(-) diff --git a/src/bip.c b/src/bip.c index ca8159b..7f038a3 100644 --- a/src/bip.c +++ b/src/bip.c @@ -79,7 +79,7 @@ static void hash_binary(char *hex, unsigned char **password, unsigned int *seed) if (strlen(hex) != 40) fatal("Incorrect password format %s\n", hex); - md5 = bip_malloc(20); + md5 = bip_malloc((size_t) 20); for (i = 0; i < 20; i++) { sscanf(hex + 2 * i, "%02x", &buf); md5[i] = buf; @@ -175,7 +175,7 @@ try_again: f = fopen(conf_pid_file, "r"); if (f) goto pid_is_there; - if (gethostname(hname, 511) == -1) + if (gethostname(hname, (size_t)511) == -1) fatal("%s %s", "gethostname", strerror(errno)); hname[511] = 0; snprintf(longpath, longpath_max - 1, "%s.%s.%ld", conf_pid_file, hname, @@ -299,7 +299,7 @@ static int add_network(bip_t *bip, list_t *data) n->serverv = NULL; n->serverc = 0; } else { - n = bip_calloc(sizeof(struct network), 1); + n = bip_calloc(sizeof(struct network), (size_t)1); hash_insert(&bip->networks, name, n); } @@ -527,6 +527,10 @@ static int add_connection(bip_t *bip, struct bipuser *user, list_t *data) case LEX_BACKLOG: ci->backlog = t2->ndata; break; + default: + conf_die(bip, "Unknown keyword in channel block (%d)", + t2->type); + return 0; } if (t2->tuple_type == TUPLE_STR && t2->pdata) free(t2->pdata); @@ -694,7 +698,7 @@ static int add_user(bip_t *bip, list_t *data, struct historical_directives *hds) } u = hash_get(&bip->users, name); if (!u) { - u = bip_calloc(sizeof(struct bipuser), 1); + u = bip_calloc(sizeof(struct bipuser), (size_t) 1); hash_insert(&bip->users, name, u); hash_init(&u->connections, HASH_NOCASE); u->admin = 0; @@ -1757,7 +1761,7 @@ void _bip_notify(struct link_client *ic, char *fmt, va_list ap) else nick = LINK(ic)->prev_nick; - vsnprintf(str, 4095, fmt, ap); + vsnprintf(str, (size_t)4095, fmt, ap); str[4095] = 0; WRITE_LINE2(CONN(ic), P_IRCMASK, (LINK(ic)->user->bip_use_notice ? "NOTICE" : "PRIVMSG"), nick, str); diff --git a/src/bip_main.c b/src/bip_main.c index 858a237..0241b3d 100644 --- a/src/bip_main.c +++ b/src/bip_main.c @@ -99,7 +99,7 @@ static void log_file_setup(void) if (conf_log_system && conf_daemonize) { if (conf_global_log_file && conf_global_log_file != stderr) fclose(conf_global_log_file); - snprintf(buf, 4095, "%s/bip.log", conf_log_root); + snprintf(buf, (size_t) 4095, "%s/bip.log", conf_log_root); FILE *f = fopen(buf, "a"); if (!f) fatal("Can't open %s: %s", buf, strerror(errno)); @@ -295,7 +295,7 @@ int main(int argc, char **argv) pid = daemonize(); else pid = getpid(); - snprintf(buf, 29, "%ld\n", (long unsigned int)pid); + snprintf(buf, (size_t) 29, "%lu\n", (unsigned long int)pid); write(fd, buf, strlen(buf)); close(fd); diff --git a/src/connection.c b/src/connection.c index 44a1e04..f4cb28e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -2,7 +2,8 @@ * $Id: connection.c,v 1.98 2005/04/12 19:34:35 nohar Exp $ * * This file is part of the bip project - * Copyright (C) 2004 2005 Arnaud Cornet and Loïc Gomez + * Copyright (C) 2004,2005 Arnaud Cornet + * Copyright (C) 2004,2005,2022 Loïc Gomez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -319,7 +320,12 @@ static int _write_socket(connection_t *cn, char *message) * Shitty: we might have written a partial line, so we hack the line... * Callers of _write_socket muse provide a writable message */ +// this might be the same +#if EWOULDBLOCK == EAGAIN + if (errno == EAGAIN || errno == EINPROGRESS) { +#else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) { +#endif memmove(message, message + tcount, size - tcount + 1); return WRITE_KEEP; } @@ -1101,8 +1107,8 @@ static connection_t *connection_init(int anti_flood, int ssl, int timeout, char *incoming; list_t *outgoing; - conn = (connection_t *)bip_calloc(sizeof(connection_t), 1); - incoming = (char *)bip_malloc(CONN_BUFFER_SIZE); + conn = (connection_t *)bip_calloc(sizeof(connection_t), (size_t)1); + incoming = (char *)bip_malloc((size_t)CONN_BUFFER_SIZE); outgoing = list_new(NULL); conn->anti_flood = anti_flood; @@ -1260,7 +1266,7 @@ connection_t *listen_new(char *hostname, int port, int ssl) connection_t *conn; char portbuf[20]; /* TODO: allow litteral service name in the function interface */ - if (snprintf(portbuf, 20, "%d", port) >= 20) + if (snprintf(portbuf, (size_t)20, "%d", port) >= 20) portbuf[19] = '\0'; /* @@ -1296,7 +1302,7 @@ static SSL_CTX *SSL_init_context(char *ciphers) SSL_load_error_strings(); errbio = BIO_new_fp(conf_global_log_file, BIO_NOCLOSE); - ssl_cx_idx = SSL_get_ex_new_index(0, "bip connection_t", + ssl_cx_idx = SSL_get_ex_new_index((size_t)0, "bip connection_t", NULL, NULL,NULL); flags = O_RDONLY; @@ -1309,7 +1315,7 @@ static SSL_CTX *SSL_init_context(char *ciphers) } do { - ret = read(fd, buf, 1024); + ret = read(fd, buf, (size_t)1024); if (ret <= 0) { mylog(LOG_ERROR,"/dev/random: %s", strerror(errno)); @@ -1573,6 +1579,8 @@ static connection_t *_connection_new_SSL(char *dsthostname, char *dstport, mylog(LOG_ERROR, "Can't open SSL certificate check store! Check path " "and permissions."); return conn; + default: + fatal("Unknown SSL cert check mode."); } switch (conn->ssl_check_mode) { @@ -1639,10 +1647,10 @@ connection_t *connection_new(char *dsthostname, int dstport, char *srchostname, (void)ssl_client_certfile; #endif /* TODO: allow litteral service name in the function interface */ - if (snprintf(dstportbuf, 20, "%d", dstport) >= 20) + if (snprintf(dstportbuf, (size_t)20, "%d", dstport) >= 20) dstportbuf[19] = '\0'; if (srcport) { - if (snprintf(srcportbuf, 20, "%d", srcport) >= 20) + if (snprintf(srcportbuf, (size_t)20, "%d", srcport) >= 20) srcportbuf[19] = '\0'; tmp = srcportbuf; } else @@ -1807,7 +1815,7 @@ static char *socket_ip(int fd, int remote) return NULL; } - ip = bip_malloc(65); + ip = bip_malloc((size_t)65); switch (addr.sa_family) { case AF_INET: diff --git a/src/irc.c b/src/irc.c index 056b298..7caad3b 100644 --- a/src/irc.c +++ b/src/irc.c @@ -82,7 +82,7 @@ static char *sasl_mechanism_to_text(int sasl_mechanism); struct channel *channel_new(const char *name) { struct channel *chan; - chan = bip_calloc(sizeof(struct channel), 1); + chan = bip_calloc(sizeof(struct channel), (size_t)1); chan->name = bip_strdup(name); hash_init(&chan->ovmasks, HASH_NOCASE); return chan; @@ -114,7 +114,7 @@ list_t *channel_name_list(struct link_server *server, struct channel *c) list_t *ret; hash_iterator_t hi; size_t len = 0; - char *str = bip_malloc(NAMESIZE + 1); + char *str = bip_malloc((size_t)(NAMESIZE + 1)); ret = list_new(NULL); *str = 0; @@ -127,7 +127,7 @@ list_t *channel_name_list(struct link_server *server, struct channel *c) if (len + strlen(nick) + 2 + (ovmask ? 1 : 0) >= NAMESIZE) { list_add_last(ret, str); - str = bip_malloc(NAMESIZE + 1); + str = bip_malloc((size_t)(NAMESIZE + 1)); *str = 0; len = 0; } @@ -250,7 +250,7 @@ static void irc_server_connected(struct link_server *server) list_iterator_t itocs; for (list_it_init(&LINK(server)->on_connect_send, &itocs); list_it_item(&itocs); list_it_next(&itocs)) { - ssize_t len = strlen(list_it_item(&itocs)) + 2; + size_t len = strlen(list_it_item(&itocs)) + 2; char *str = bip_malloc(len + 1); sprintf(str, "%s\r\n", (char *)list_it_item(&itocs)); write_line(CONN(server), str); @@ -517,9 +517,9 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server, if (LINK(server)->ignore_server_capab && irc_line_elem_equals(line, i, "CAPAB")) irc_line_drop(line, i); - else if (!strncmp(irc_line_elem(line, i), "CHANMODES=", 10)) + else if (!strncmp(irc_line_elem(line, i), "CHANMODES=", (size_t)10)) server_set_chanmodes(server, irc_line_elem(line, i) + 10); - else if (!strncmp(irc_line_elem(line, i), "PREFIX=(", 8)) + else if (!strncmp(irc_line_elem(line, i), "PREFIX=(", (size_t)8)) server_set_prefix(server, irc_line_elem(line, i) + 7); } } @@ -1790,8 +1790,8 @@ static int irc_mode_channel(struct link_server *s, struct channel *channel, static char *irc_timestamp(void) { - char *ts = bip_malloc(21); - snprintf(ts, 20, "%ld", (long int)time(NULL)); + char *ts = bip_malloc((size_t)23); + snprintf(ts, (size_t)22, "%ld", (long int)time(NULL)); return ts; } @@ -2149,7 +2149,7 @@ static struct link_client *irc_accept_new(connection_t *conn) if (!newconn) return NULL; - ircc = bip_calloc(sizeof(struct link_client), 1); + ircc = bip_calloc(sizeof(struct link_client), (size_t)1); CONN(ircc) = newconn; TYPE(ircc) = IRC_TYPE_LOGGING_CLIENT; CONN(ircc)->user_data = ircc; @@ -2254,7 +2254,7 @@ struct link_client *irc_client_new(void) { struct link_client *c; - c = bip_calloc(sizeof(struct link_client), 1); + c = bip_calloc(sizeof(struct link_client), (size_t)1); list_init(&c->who_queue, list_ptr_cmp); return c; @@ -2264,7 +2264,7 @@ struct link_server *irc_server_new(struct link *link, connection_t *conn) { struct link_server *s; - s = bip_calloc(sizeof(struct link_server), 1); + s = bip_calloc(sizeof(struct link_server), (size_t)1); TYPE(s) = IRC_TYPE_SERVER; hash_init(&s->channels, HASH_NOCASE); @@ -2445,7 +2445,7 @@ void oidentd_dump(bip_t *bip) content = (char *)bip_malloc(stats.st_size + 1); - if (fread(content, 1, stats.st_size, f) != + if (fread(content, (size_t)1, stats.st_size, f) != (size_t)stats.st_size) { mylog(LOG_WARN, "Can't read %s fully", bip->oidentdpath); @@ -2458,10 +2458,9 @@ void oidentd_dump(bip_t *bip) bipstart = strstr(content, BIP_OIDENTD_START); if (bipstart != NULL) { - /* We have some config left, rewrite the file - * completely */ - fseek(f, SEEK_SET, 0); - if (ftruncate(fileno(f), 0) == -1) { + // We have some config left, rewrite the file completely + fseek(f, (long)SEEK_SET, (int)0); + if (ftruncate(fileno(f), (off_t)0) == -1) { mylog(LOG_DEBUG, "Can't reset %s size", bip->oidentdpath); free(content); @@ -2756,7 +2755,7 @@ void irc_client_free(struct link_client *cli) struct link *irc_link_new(void) { struct link *link; - link = bip_calloc(sizeof(struct link), 1); + link = bip_calloc(sizeof(struct link), (size_t)1); link->l_server = NULL; hash_init(&link->chan_infos, HASH_NOCASE); @@ -2845,7 +2844,7 @@ static void server_set_chanmodes(struct link_server *l, const char *modes) modes = cur + 1; } else { // emptry string - dup = bip_calloc(1, sizeof(char)); + dup = bip_calloc((size_t)1, sizeof(char)); } mylog(LOG_DEBUGVERB, "[%s] Modes: '%s'", LINK(l)->name, dup); array_push(&l->chanmodes, dup); diff --git a/src/irc.h b/src/irc.h index 5d7a4c8..e2070bd 100644 --- a/src/irc.h +++ b/src/irc.h @@ -225,7 +225,7 @@ struct chan_info { int backlog; }; -#define chan_info_new() bip_calloc(sizeof(struct chan_info), 1) +#define chan_info_new() bip_calloc(sizeof(struct chan_info), (size_t)1) struct link_server { struct link_connection _link_c; @@ -274,7 +274,6 @@ struct link_server *irc_server_new(struct link *link, connection_t *conn); void irc_server_free(struct link_server *is); struct client *client_new(void); void irc_main(bip_t *); -int ischannel(char p); void irc_client_close(struct link_client *); void irc_client_free(struct link_client *); struct link *irc_link_new(void); diff --git a/src/line.h b/src/line.h index 52a8d93..729bc86 100644 --- a/src/line.h +++ b/src/line.h @@ -2,7 +2,8 @@ * $Id$ * * This file is part of the bip project - * Copyright (C) 2004 2005 Arnaud Cornet and Loïc Gomez + * Copyright (C) 2004,2005 Arnaud Cornet + * Copyright (C) 2004,2005,2022 Loïc Gomez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,7 +85,7 @@ struct line { void irc_line_init(struct line *l); void _irc_line_deinit(struct line *l); -struct line *irc_line_new(); +struct line *irc_line_new(void); void irc_line_write(struct line *l, connection_t *c); void irc_line_append(struct line *l, const char *s); struct line *irc_line_new_from_string(char *str); diff --git a/src/log.c b/src/log.c index b6fdc55..8e5aefe 100644 --- a/src/log.c +++ b/src/log.c @@ -2,7 +2,8 @@ * $Id: log.c,v 1.56 2005/04/21 06:58:50 nohar Exp $ * * This file is part of the bip project - * Copyright (C) 2004 Arnaud Cornet and Loïc Gomez + * Copyright (C) 2004 Arnaud Cornet + * Copyright (C) 2004,2022 Loïc Gomez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -83,7 +84,7 @@ int check_dir_r(char *dirname) int slash_ok = 1; while (*tmp == '/') { if (slash_ok) { - strncpy(dir + count, "/", 2); + strncpy(dir + count, "/", (size_t)2); count++; slash_ok = 0; } @@ -140,15 +141,15 @@ char *log_build_filename(log_t *logdata, const char *destination) char *dest = bip_strdup(destination); strtolower(dest); - logfile = (char *)bip_malloc(MAX_PATH_LEN + 1); + logfile = (char *)bip_malloc((size_t)MAX_PATH_LEN + 1); time(&s); now = localtime(&s); - strftime(year, 5, "%Y", now); - strftime(day, 3, "%d", now); - strftime(month, 3, "%m", now); - strftime(hour, 3, "%H", now); - snprintf(logfile, MAX_PATH_LEN, "%s/%s", conf_log_root, + strftime(year, (size_t)5, "%Y", now); + strftime(day, (size_t)3, "%d", now); + strftime(month, (size_t)3, "%m", now); + strftime(hour, (size_t)3, "%H", now); + snprintf(logfile, (size_t)MAX_PATH_LEN, "%s/%s", conf_log_root, conf_log_format); replace_var(logfile, "%u", logdata->user->name, MAX_PATH_LEN); replace_var(logfile, "%n", logdata->network, MAX_PATH_LEN); @@ -280,7 +281,7 @@ static int log_add_file(log_t *logdata, const char *destination, return 0; } - if (fseek(f, 0, SEEK_END) == -1) { + if (fseek(f, (long)0, SEEK_END) == -1) { mylog(LOG_ERROR, "fseek(%s) %s", uniq_fname, strerror(errno)); free(uniq_fname); @@ -299,7 +300,7 @@ static int log_add_file(log_t *logdata, const char *destination, store = hash_get(&logdata->logfgs, destination); if (!store) { - store = bip_calloc(sizeof(logstore_t), 1); + store = bip_calloc(sizeof(logstore_t), (size_t)1); list_init(&store->file_group, NULL); store->name = bip_strdup(destination); store->skip_advance = 0; @@ -433,7 +434,7 @@ logstore_t *log_find_file(log_t *logdata, const char *destination) void log_join(log_t *logdata, const char *ircmask, const char *channel) { - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- %s has joined %s", timestamp(), ircmask, channel); log_write(logdata, channel, logdata->buffer); @@ -443,11 +444,11 @@ void log_part(log_t *logdata, const char *ircmask, const char *channel, const char *message) { if (message) - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- %s has left %s [%s]", timestamp(), ircmask, channel, message); else - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- %s has left %s", timestamp(), ircmask, channel); log_write(logdata, channel, logdata->buffer); @@ -456,7 +457,7 @@ void log_part(log_t *logdata, const char *ircmask, const char *channel, void log_kick(log_t *logdata, const char *ircmask, const char *channel, const char *who, const char *message) { - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- %s has been kicked by %s [%s]", timestamp(), who, ircmask, message); log_write(logdata, channel, logdata->buffer); @@ -465,7 +466,7 @@ void log_kick(log_t *logdata, const char *ircmask, const char *channel, void log_quit(log_t *logdata, const char *ircmask, const char *channel, const char *message) { - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- %s has quit [%s]", timestamp(), ircmask, message); log_write(logdata, channel, logdata->buffer); @@ -487,7 +488,7 @@ void log_nick(log_t *logdata, const char *ircmask, const char *channel, } free(oldnick); - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- %s is now known as %s", timestamp(), ircmask, newnick); log_write(logdata, channel, logdata->buffer); @@ -514,16 +515,16 @@ static void do_log_privmsg(log_t *logdata, const char *storage, int src, if (*message == '+' || *message == '-') real_message++; - if (strncmp(real_message, "\001ACTION ", 8) != 0) + if (strncmp(real_message, "\001ACTION ", (size_t)8) != 0) return; msg = bip_strdup(real_message); *(msg + strlen(msg) - 1) = '\0'; - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s %c * %s %s", timestamp(), dir, from, msg + 8); free(msg); } else { - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s %c %s: %s", timestamp(), dir, from, message); } @@ -571,7 +572,7 @@ void log_cli_notice(log_t *logdata, const char *ircmask, void log_topic(log_t *logdata, const char *ircmask, const char *channel, const char *message) { - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- %s changed topic of %s to: %s", timestamp(), ircmask, channel, message); log_write(logdata, channel, logdata->buffer); @@ -579,7 +580,7 @@ void log_topic(log_t *logdata, const char *ircmask, const char *channel, void log_init_topic(log_t *logdata, const char *channel, const char *message) { - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Topic for %s: %s", timestamp(), channel, message); log_write(logdata, channel, logdata->buffer); @@ -594,13 +595,13 @@ void log_init_topic_time(log_t *logdata, const char *channel, const char *who, seconds = atoi(when); time = localtime(&seconds); - timestr = (char *)bip_malloc(50 + 1); + timestr = (char *)bip_malloc((size_t)50 + 1); timestr[0] = '\0'; if (time) - strftime(timestr, 50, "%A %d %B %Y, %H:%M:%S", time); + strftime(timestr, (size_t)50, "%A %d %B %Y, %H:%M:%S", time); timestr[50] = '\0'; - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Topic set by %s [%s]", timestamp(), who, timestr); free(timestr); @@ -611,15 +612,15 @@ void log_mode(log_t *logdata, const char *ircmask, const char *channel, const char *modes, array_t *mode_args) { int i; - char *tmpbuf = bip_malloc(LOGLINE_MAXLEN + 1); - char *tmpbuf2 = bip_malloc(LOGLINE_MAXLEN + 1); + char *tmpbuf = bip_malloc((size_t)LOGLINE_MAXLEN + 1); + char *tmpbuf2 = bip_malloc((size_t)LOGLINE_MAXLEN + 1); char *tmp; - snprintf(tmpbuf, LOGLINE_MAXLEN, "%s -!- mode/%s [%s", timestamp(), - channel, modes); + snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN, + "%s -!- mode/%s [%s", timestamp(), channel, modes); if (mode_args) { for (i = 0; i < array_count(mode_args); i++) { - snprintf(tmpbuf2, LOGLINE_MAXLEN, "%s %s", tmpbuf, + snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s", tmpbuf, (char *)array_get(mode_args, i)); tmp = tmpbuf; tmpbuf = tmpbuf2; @@ -627,7 +628,8 @@ void log_mode(log_t *logdata, const char *ircmask, const char *channel, } } - snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s] by %s", tmpbuf, ircmask); + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s", + tmpbuf, ircmask); log_write(logdata, channel, logdata->buffer); free(tmpbuf); @@ -637,7 +639,7 @@ void log_mode(log_t *logdata, const char *ircmask, const char *channel, void log_disconnected(log_t *logdata) { hash_iterator_t hi; - snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s -!- Disconnected" + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Disconnected" " from server...", timestamp()); for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi); hash_it_next(&hi)) @@ -649,7 +651,7 @@ void log_ping_timeout(log_t *logdata) list_t *l = log_backlogs(logdata); char *s; - snprintf(logdata->buffer, LOGLINE_MAXLEN, + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Ping timeout with server...", timestamp()); while ((s = list_remove_first(l))) { log_write(logdata, s, logdata->buffer); @@ -663,7 +665,7 @@ void log_connected(log_t *logdata) { hash_iterator_t hi; - snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s -!- Connected to" + snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Connected to" " server...", timestamp()); for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi); hash_it_next(&hi)) { @@ -860,7 +862,7 @@ char *log_beautify(log_t *logdata, const char *buf, const char *storename, lots = p - sots; p++; - if (strncmp(p, "-!-", 3) == 0) { + if (strncmp(p, "-!-", (size_t)3) == 0) { if (logdata->user->bl_msg_only) return NULL; else @@ -1005,7 +1007,7 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf, } } else { //mylog(LOG_ERROR, "bread Seeking %s to %d", lf->filename, 0); - if (fseek(lf->file, 0, SEEK_SET)) { + if (fseek(lf->file, (long)0, SEEK_SET)) { mylog(LOG_ERROR, "Can't seek in %s", lf->filename); list_add_last(res, _log_wrap(store->name, "Error seeking in logfile")); @@ -1013,7 +1015,7 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf, } } - buf = bip_malloc(LOGLINE_MAXLEN + 1); + buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1); for(;;) { if (!fgets(buf, LOGLINE_MAXLEN, lf->file)) { if (ferror(lf->file)) { @@ -1108,8 +1110,8 @@ static char *_log_wrap(const char *dest, const char *line) char *buf; size_t count; - buf = bip_malloc(LOGLINE_MAXLEN + 1); - count = snprintf(buf, LOGLINE_MAXLEN + 1, + buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1); + count = snprintf(buf, (size_t)LOGLINE_MAXLEN + 1, ":" P_IRCMASK " PRIVMSG %s :%s\r\n", dest, line); if (count >= LOGLINE_MAXLEN + 1) { mylog(LOG_DEBUG, "line too long"); @@ -1127,7 +1129,7 @@ static int _log_write(log_t *logdata, logstore_t *store, size_t len; static char tmpstr[LOGLINE_MAXLEN + 1]; - strncpy(tmpstr, str, LOGLINE_MAXLEN); + strncpy(tmpstr, str, (size_t)LOGLINE_MAXLEN); tmpstr[LOGLINE_MAXLEN] = 0; if (store->memlog) { @@ -1149,7 +1151,7 @@ static int _log_write(log_t *logdata, logstore_t *store, len = strlen(tmpstr); nbwrite = fwrite(tmpstr, sizeof(char), len, lf->file); - nbwrite += fwrite("\n", sizeof(char), 1, lf->file); + nbwrite += fwrite("\n", sizeof(char), (size_t)1, lf->file); log_updatelast(lf); if (nbwrite != len + 1) mylog(LOG_ERROR, "Error writing to %s logfile", lf->filename); @@ -1202,11 +1204,11 @@ log_t *log_new(struct bipuser *user, const char *network) { log_t *logdata; - logdata = (log_t *)bip_calloc(sizeof(log_t), 1); + logdata = (log_t *)bip_calloc(sizeof(log_t), (size_t)1); logdata->user = user; logdata->network = bip_strdup(network); hash_init(&logdata->logfgs, HASH_NOCASE); - logdata->buffer = (char *)bip_malloc(LOGLINE_MAXLEN + 1); + logdata->buffer = (char *)bip_malloc((size_t)LOGLINE_MAXLEN + 1); logdata->buffer[LOGLINE_MAXLEN - 1] = 0; // debug logdata->buffer[LOGLINE_MAXLEN] = 0; logdata->connected = 0; diff --git a/src/md5.c b/src/md5.c index 8f4876b..e408157 100644 --- a/src/md5.c +++ b/src/md5.c @@ -1,7 +1,8 @@ /* * RFC 1321 compliant MD5 implementation * - * Copyright (C) 2001-2003 Christophe Devine + * Copyright (C) 2001-2003 Christophe Devine + * Copyright (C) 2022 Loïc Gomez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -238,7 +239,7 @@ void md5_finish( md5_context *ctx, uint8 digest[16] ) padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); md5_update( ctx, md5_padding, padn ); - md5_update( ctx, msglen, 8 ); + md5_update( ctx, msglen, (unsigned long)8 ); PUT_UINT32( ctx->state[0], digest, 0 ); PUT_UINT32( ctx->state[1], digest, 4 ); @@ -365,15 +366,15 @@ unsigned char *chash_double(char *str, unsigned int seed) ptr[3] = seed & 0xff; memcpy(ptr + 4, str, length - 4); - md5 = bip_malloc(16 + 4); - memcpy(md5, ptr, 4); + md5 = bip_malloc((size_t)16 + 4); + memcpy(md5, ptr, (size_t)4); md5_starts(&ctx); md5_update(&ctx, ptr, length); md5_finish(&ctx, md5 + 4); md5_starts(&ctx); - md5_update(&ctx, md5, 20); + md5_update(&ctx, md5, (unsigned long)20); md5_finish(&ctx, md5 + 4); free(ptr); return md5; diff --git a/src/util.c b/src/util.c index 6d69725..eb48f46 100644 --- a/src/util.c +++ b/src/util.c @@ -36,7 +36,7 @@ void memory_fatal(void) { fflush(conf_global_log_file); #define OOMMSG "Out of memory.\n" - fwrite(OOMMSG, 1, strlen(OOMMSG), conf_global_log_file); + fwrite(OOMMSG, (size_t)1, strlen(OOMMSG), conf_global_log_file); #undef OOMMSG fflush(conf_global_log_file); exit(28); @@ -199,7 +199,7 @@ char *timestamp(void) time(&tv); tm = localtime(&tv); - strftime(ts, 20, "%d-%m-%Y %H:%M:%S", tm); + strftime(ts, (size_t)20, "%d-%m-%Y %H:%M:%S", tm); return ts; } @@ -212,7 +212,7 @@ char *hrtime(time_t s) return "never"; tm = localtime(&s); - strftime(ts, 20, "%d-%m-%Y %H:%M:%S", tm); + strftime(ts, (size_t)20, "%d-%m-%Y %H:%M:%S", tm); return ts; }