From: Sebastian Harl Date: Sun, 12 Jan 2014 17:37:04 +0000 (+0100) Subject: Fixed memory errors identified by LLVM's AddressSanitizer. X-Git-Tag: sysdb-0.1.0~239 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=7eae8c92fd40a050f9ce4a7132191fbcef810dc0;ds=sidebyside Fixed memory errors identified by LLVM's AddressSanitizer. Test performed as: ./configure CC=clang \ CFLAGS="-O0 -g -fsanitize=address -fno-omit-frame-pointer" \ LDFLAGS=-fsanitize=address make clean all test See also http://clang.llvm.org/docs/AddressSanitizer.html --- diff --git a/src/frontend/sock.c b/src/frontend/sock.c index 0c4829e..aa7cab0 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -238,7 +238,7 @@ listener_create(sdb_fe_socket_t *sock, const char *address) } listener = realloc(sock->listeners, - sock->listeners_num * sizeof(*sock->listeners)); + (sock->listeners_num + 1) * sizeof(*sock->listeners)); if (! listener) { char buf[1024]; sdb_log(SDB_LOG_ERR, "frontend: Failed to allocate memory: %s", diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index da992c9..62b6f45 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -320,7 +320,7 @@ sdb_unixsock_client_recv(sdb_unixsock_client_t *client, buffer[buflen - 1] = '\0'; buflen = strlen(buffer); - while ((buffer[buflen - 1] == '\n') || (buffer[buflen - 1] == '\r')) { + while (buflen && ((buffer[buflen - 1] == '\n') || (buffer[buflen - 1] == '\r'))) { buffer[buflen - 1] = '\0'; --buflen; }