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 0c4829e2efc4d3737fb9cf4a5f21cf3df5fa59b5..aa7cab068b115d07d2008eceb78347b99c5c19cd 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 da992c94b51601024bc03e2988ca9ff8d7a1e9d8..62b6f45aa404f360ed1f623c07362dcb2c2e26b0 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;
        }