From 7eae8c92fd40a050f9ce4a7132191fbcef810dc0 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 12 Jan 2014 18:37:04 +0100 Subject: [PATCH] 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 --- src/frontend/sock.c | 2 +- src/utils/unixsock.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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; } -- 2.30.2