sFlow: clear the padding
authorFrancesco Fusco <ffusco@redhat.com>
Thu, 19 Dec 2013 17:16:24 +0000 (18:16 +0100)
committerBen Pfaff <blp@nicira.com>
Mon, 13 Jan 2014 21:32:51 +0000 (13:32 -0800)
putString pads the string to the 4-byte boundary without
clearing the "padded" memory. This patch simply set the
padding to zero.

Signed-off-by: Francesco Fusco <ffusco@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/sflow_receiver.c

index 3e5a67a..e6fc9a7 100644 (file)
@@ -198,6 +198,10 @@ inline static void putString(SFLReceiver *receiver, SFLString *s)
     putNet32(receiver, s->len);
     memcpy(receiver->sampleCollector.datap, s->str, s->len);
     receiver->sampleCollector.datap += (s->len + 3) / 4; /* pad to 4-byte boundary */
+    if ((s->len % 4) != 0){
+        u_int8_t padding = 4 - (s->len % 4);
+        memset(((u_int8_t*)receiver->sampleCollector.datap)-padding, 0, padding);
+    }
 }
 
 inline static u_int32_t stringEncodingLength(SFLString *s) {