Code

Fixed memory errors identified by LLVM's AddressSanitizer.
authorSebastian Harl <sh@tokkee.org>
Sun, 12 Jan 2014 17:37:04 +0000 (18:37 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 12 Jan 2014 17:37:04 +0000 (18:37 +0100)
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
src/utils/unixsock.c

index 0c4829e..aa7cab0 100644 (file)
@@ -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",
index da992c9..62b6f45 100644 (file)
@@ -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;
        }