libcollectdclient: Fix off-by-one error when reading the username.
authorFlorian Forster <octo@collectd.org>
Tue, 2 May 2017 08:26:40 +0000 (10:26 +0200)
committerFlorian Forster <octo@collectd.org>
Tue, 2 May 2017 08:26:40 +0000 (10:26 +0200)
The allocated buffer includes a null byte, but the network packet doesn't.
That means we were reading one byte too many from the buffer, overwriting
the terminating null byte in the buffer.

src/libcollectdclient/network_parse.c

index 7139c9b..83a05d4 100644 (file)
@@ -441,7 +441,7 @@ static int parse_encrypt_aes256(void *data, size_t data_size,
     return ENOMEM;
   char username[((size_t)username_len) + 1];
   memset(username, 0, sizeof(username));
-  if (buffer_next(b, username, sizeof(username)))
+  if (buffer_next(b, username, (size_t)username_len))
     return EINVAL;
 
   char const *password = opts->password_lookup(username);