From a4b101cea82654ab3eb028b794b8776238ddd82c Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 29 Dec 2008 14:04:51 +0100 Subject: [PATCH 1/8] ensure null terminated str --- src/bipmkpw.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bipmkpw.c b/src/bipmkpw.c index 9a79a44..20fb0b4 100644 --- a/src/bipmkpw.c +++ b/src/bipmkpw.c @@ -33,23 +33,23 @@ void readpass(char *buffer, int buflen) fprintf(stderr, "Unable to open tty: %s\n", strerror(errno)); exit(1); } - + struct termios tt, ttback; memset(&ttback, 0, sizeof(ttback)); if (tcgetattr(ttyfd, &ttback) < 0) { - printf("tcgetattr failed: %s\n", strerror(errno)); + fprintf(stderr, "tcgetattr failed: %s\n", strerror(errno)); exit(1); } - + memcpy(&tt, &ttback, sizeof(ttback)); tt.c_lflag &= ~(ICANON|ECHO); if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) { - printf("tcsetattr failed: %s\n", strerror(errno)); + fprintf(stderr, "tcsetattr failed: %s\n", strerror(errno)); exit(1); } - + write(ttyfd, "Password: ", 10); - + int idx = 0; while (idx < buflen) { read(ttyfd, buffer+idx, 1); @@ -59,9 +59,9 @@ void readpass(char *buffer, int buflen) } idx++; } - + write(ttyfd, "\n", 1); - + tcsetattr(ttyfd, TCSANOW, &ttback); close(ttyfd); } @@ -74,11 +74,12 @@ int main(void) unsigned int seed; readpass(str, 256); + str[255] = 0; // the time used to type the pass is entropy srand(time(NULL)); seed = rand(); - + md5 = chash_double(str, seed); for (i = 0; i < 20; i++) printf("%02x", md5[i]); From b9f86d544d6422f61870f1326cf1197a959530fb Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 29 Dec 2008 14:07:09 +0100 Subject: [PATCH 2/8] Add autoheader in boostrap script. --- bootstrap | 1 + configure.in | 1 + 2 files changed, 2 insertions(+) diff --git a/bootstrap b/bootstrap index 0576878..a2d497d 100755 --- a/bootstrap +++ b/bootstrap @@ -5,6 +5,7 @@ set -e aclocal +autoheader autoconf automake --add-missing --copy -Wall diff --git a/configure.in b/configure.in index a3b19cf..8023f4f 100644 --- a/configure.in +++ b/configure.in @@ -3,6 +3,7 @@ AM_CONFIG_HEADER(src/config.h) AM_INIT_AUTOMAKE(bip,0.8.0) AC_PROG_CC AC_PROG_INSTALL + AM_PROG_LEX AC_PROG_YACC From 0ecb77617cedbf0b82c9f1ed78af61d47a6c3a32 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 29 Dec 2008 15:31:32 +0100 Subject: [PATCH 3/8] Sanitize bip_(m|re)alloc size. --- src/conf.y | 8 ++------ src/irc.c | 3 +-- src/util.c | 13 +++++++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/conf.y b/src/conf.y index b90c101..3c23ce7 100644 --- a/src/conf.y +++ b/src/conf.y @@ -36,9 +36,7 @@ list_t *root_list; struct tuple *tuple_i_new(int type, int i) { struct tuple *t; - t = malloc(sizeof(struct tuple)); - if (!t) - fatal("malloc"); + t = bip_malloc(sizeof(struct tuple)); t->type = type; t->ndata = i; t->tuple_type = TUPLE_INT; @@ -48,9 +46,7 @@ struct tuple *tuple_i_new(int type, int i) struct tuple *tuple_p_new(int type, void *p) { struct tuple *t; - t = malloc(sizeof(struct tuple)); - if (!t) - fatal("malloc"); + t = bip_malloc(sizeof(struct tuple)); t->type = type; t->pdata = p; return t; diff --git a/src/irc.c b/src/irc.c index 9b45fae..aafc584 100644 --- a/src/irc.c +++ b/src/irc.c @@ -88,8 +88,7 @@ char *nick_from_ircmask(const char *mask) char *ret; size_t len; - if (!mask) - fatal("nick_from_ircmask"); + assert(mask); while (*nick && *nick != '!') nick++; diff --git a/src/util.c b/src/util.c index 8f6c90f..c305819 100644 --- a/src/util.c +++ b/src/util.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,11 @@ void memory_fatal(void) void *bip_malloc(size_t size) { - void *r = malloc(size); + void *r; + + assert(size < INT_MAX / 4); + + r = malloc(size); if (!r) memory_fatal(); return r; @@ -57,7 +62,11 @@ void *bip_calloc(size_t nmemb, size_t size) void *bip_realloc(void *ptr, size_t size) { - void *r = realloc(ptr, size); + void *r; + + assert(size < INT_MAX / 4); + + r = realloc(ptr, size); if (size > 0 && r == NULL) memory_fatal(); return r; From 2ef3506a22deb016055d66d2c036976028d948a1 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Tue, 30 Dec 2008 11:12:52 +0100 Subject: [PATCH 4/8] Remove useless null check. Cycle server on early connection problem. --- src/connection.c | 2 -- src/irc.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/connection.c b/src/connection.c index c95c7a6..bfdec8b 100644 --- a/src/connection.c +++ b/src/connection.c @@ -897,8 +897,6 @@ static void create_socket(char *dsthostname, char *dstport, char *srchostname, cn->connected = CONN_ERROR; cdata = (struct connecting_data *) bip_malloc(sizeof(struct connecting_data)); - if (!cdata) - fatal("Out of memory."); cdata->dst = cdata->src = cdata->cur = NULL; err = getaddrinfo(dsthostname, dstport, &hint, &cdata->dst); diff --git a/src/irc.c b/src/irc.c index aafc584..15b3a7e 100644 --- a/src/irc.c +++ b/src/irc.c @@ -2127,6 +2127,7 @@ connection_t *irc_server_connect(struct link *link) if (conn->handle == -1) { mylog(LOG_INFO, "Cannot connect."); connection_free(conn); + server_next(link); return NULL; } From aab5e61c050d28ae049d46d2a50781c4a2b6fd94 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 5 Jan 2009 22:52:25 +0100 Subject: [PATCH 5/8] Fix leak. --- src/irc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/irc.c b/src/irc.c index 15b3a7e..4c029ee 100644 --- a/src/irc.c +++ b/src/irc.c @@ -1489,9 +1489,12 @@ static int irc_part(struct link_server *server, struct line *line) if (!line->origin) return ERR_PROTOCOL; s_nick = nick_from_ircmask(line->origin); - if (!hash_includes(&channel->ovmasks, s_nick)) + if (!hash_includes(&channel->ovmasks, s_nick)) { + free(s_nick); return ERR_PROTOCOL; + } hash_remove(&channel->ovmasks, s_nick); + free(s_nick); log_part(LINK(server)->log, line->origin, s_chan, irc_line_count(line) == 3 ? From 96a91cd92e6aab1c04587e5c3a77bfefcb89adff Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 5 Jan 2009 22:54:10 +0100 Subject: [PATCH 6/8] Fix leak during backlog. --- src/log.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/log.c b/src/log.c index 1965309..a2e1698 100644 --- a/src/log.c +++ b/src/log.c @@ -1280,6 +1280,8 @@ list_t *backlog_lines_from_last_mark(log_t *log, const char *bl) while ((line = log_backread(log, bl, &skip))) { if (!skip) list_add_last(ret, line); + else + free(line); } if (ischannel(*bl)) { From 00a10a9f610cda3d186ac464ba6b485b52db94b2 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 5 Jan 2009 22:56:01 +0100 Subject: [PATCH 7/8] Fix another leak. --- src/log.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/log.c b/src/log.c index a2e1698..25d5dc9 100644 --- a/src/log.c +++ b/src/log.c @@ -1069,6 +1069,7 @@ next_file: if (!logdata->lastfile_seeked) { if (fseek(lf->file, lf->backlog_offset, SEEK_SET)) { log_reinit(store); + free(buf); return _log_wrap(destination, "Error reading in logfile"); } From 217816c220905365b323acee8c81a67917e26d08 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Mon, 5 Jan 2009 22:57:27 +0100 Subject: [PATCH 8/8] And anothear nick_from_ircmask leak. --- src/irc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/irc.c b/src/irc.c index 4c029ee..1480e3f 100644 --- a/src/irc.c +++ b/src/irc.c @@ -1272,9 +1272,10 @@ static int irc_join(struct link_server *server, struct line *line) return ERR_PROTOCOL; if (!line->origin) return ERR_PROTOCOL; - s_nick = nick_from_ircmask(line->origin); + s_nick = nick_from_ircmask(line->origin); hash_insert(&channel->ovmasks, s_nick, 0); + free(s_nick); return OK_COPY; }