diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-18 01:30:30 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-18 01:30:30 +0200 |
commit | bd1f2af1db44587ab378612cd9785f9848c4f654 (patch) | |
tree | 2eb6f68f2507fffbd9ea6f694ce83039b2b16db9 /src/mds-server | |
parent | fix length of multicast messages (diff) | |
download | mds-bd1f2af1db44587ab378612cd9785f9848c4f654.tar.gz mds-bd1f2af1db44587ab378612cd9785f9848c4f654.tar.bz2 mds-bd1f2af1db44587ab378612cd9785f9848c4f654.tar.xz |
use memchr rather than strchrnul, the payload is not NUL-terminated
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-server')
-rw-r--r-- | src/mds-server/mds-server.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c index 1551dcc..2f53a12 100644 --- a/src/mds-server/mds-server.c +++ b/src/mds-server/mds-server.c @@ -878,6 +878,7 @@ int message_received(client_t* client) if ((intercept & 1)) /* from payload */ { char* payload = client->message.payload; + size_t payload_size = client->message.payload_size; if (client->message.payload_size == 0) /* All messages */ { *buf = '\0'; @@ -886,11 +887,12 @@ int message_received(client_t* client) else /* Filtered messages */ for (;;) { - char* end = strchrnul(payload, '\n'); - size_t len = (size_t)(end - payload); + char* end = memchr(payload, '\n', payload_size); + size_t len = end == NULL ? payload_size : (size_t)(end - payload); if (len == 0) { payload++; + payload_size--; break; } if (len > size) @@ -908,9 +910,10 @@ int message_received(client_t* client) memcpy(buf, payload, len); buf[len] = '\0'; add_intercept_condition(client, buf, priority, modifying, stop); - if (*end == '\0') + if (end == NULL) break; payload = end + 1; + payload_size -= len + 1; } } if ((intercept & 2)) /* "To: $(client->id)" */ |