lq plugins: ensure string termination in lq_print_cost functions
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 3 Dec 2015 15:23:06 +0000 (16:23 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 3 Dec 2015 15:43:33 +0000 (16:43 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/lq_plugin_default_ff.c
src/lq_plugin_default_ffeth.c
src/lq_plugin_default_float.c
src/lq_plugin_default_fpm.c

index 8a03193..5b17624 100644 (file)
@@ -416,6 +416,7 @@ static const char *
 default_lq_print_cost_ff(olsr_linkcost cost, struct lqtextbuffer *buffer)
 {
   snprintf(buffer->buf, sizeof(buffer->buf), "%s", fpmtoa(cost));
+  buffer->buf[sizeof(buffer->buf) - 1] = '\0';
   return buffer->buf;
 }
 
index 740b453..63328f2 100644 (file)
@@ -466,6 +466,7 @@ static const char *
 default_lq_print_cost_ffeth(olsr_linkcost cost, struct lqtextbuffer *buffer)
 {
   snprintf(buffer->buf, sizeof(buffer->buf), "%s", fpmtoa(cost));
+  buffer->buf[sizeof(buffer->buf) - 1] = '\0';
   return buffer->buf;
 }
 
index fe5f586..09baec3 100644 (file)
@@ -227,7 +227,7 @@ static const char *
 default_lq_print_cost_float(olsr_linkcost cost, struct lqtextbuffer *buffer)
 {
   snprintf(buffer->buf, sizeof(struct lqtextbuffer), "%2.3f", (double)(((float)cost) / (float)LQ_PLUGIN_LC_MULTIPLIER));
-
+  buffer->buf[sizeof(buffer->buf) - 1] = '\0';
   return buffer->buf;
 }
 
index c07903d..e1fe841 100644 (file)
@@ -239,6 +239,7 @@ static const char *
 default_lq_print_cost_fpm(olsr_linkcost cost, struct lqtextbuffer *buffer)
 {
   snprintf(buffer->buf, sizeof(buffer->buf), "%.3f", (double)(cost) / (double)LQ_FPM_LINKCOST_MULTIPLIER);
+  buffer->buf[sizeof(buffer->buf) - 1] = '\0';
   return buffer->buf;
 }