diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2017-02-15 19:02:06 +0200 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2017-02-15 19:02:06 +0200 |
| commit | a2c431ec96f7a6ed7e5c41b7ae93dc086ae541f1 (patch) | |
| tree | f3eb6bbe15833a564bb4469ccd7c0a3c3a5f2f7b /src/stream_mqtt.c | |
| parent | 0741e7d5810c1bb999b417f97dd66f5ba4cdc6c2 (diff) | |
| download | mqtt-a2c431ec96f7a6ed7e5c41b7ae93dc086ae541f1.tar.gz mqtt-a2c431ec96f7a6ed7e5c41b7ae93dc086ae541f1.zip | |
NULL terminate received strings and message payload
Diffstat (limited to 'src/stream_mqtt.c')
| -rw-r--r-- | src/stream_mqtt.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/stream_mqtt.c b/src/stream_mqtt.c index c9d0e12..3864ef3 100644 --- a/src/stream_mqtt.c +++ b/src/stream_mqtt.c @@ -10,7 +10,9 @@ int64_t StreamReadMqttString(bstring *buf, Stream *stream) if (StreamReadUint16Be(&len, stream) == -1) return -1; - result = bfromcstralloc(len, ""); + /* We need 1 extra byte for a NULL terminator. bfromcstralloc doesn't do + any size snapping. */ + result = bfromcstralloc(len+1, ""); if (!result) return -1; @@ -22,6 +24,7 @@ int64_t StreamReadMqttString(bstring *buf, Stream *stream) } result->slen = len; + result->data[len] = '\0'; *buf = result; |
