Code

Fixed gcc 7 format-truncation errors #2423
authorTaras Chornyi <tarasx.chornyi@intel.com>
Tue, 14 Nov 2017 17:17:20 +0000 (17:17 +0000)
committerMarc Fournier <marc.fournier@camptocamp.com>
Tue, 14 Nov 2017 21:14:31 +0000 (22:14 +0100)
Signed-off-by: Taras Chornyi <tarasx.chornyi@intel.com>
src/mcelog.c
src/target_notification.c
src/utils_tail_match.c

index ae5a7f549646b85bf72dfa25d3c9ead7e55e687e..8ef5c23df57fa4e0b0304474c6938dd2d713aa34 100644 (file)
@@ -75,12 +75,12 @@ struct socket_adapter_s {
 typedef struct mcelog_memory_rec_s {
   int corrected_err_total; /* x total*/
   int corrected_err_timed; /* x in 24h*/
-  char corrected_err_timed_period[DATA_MAX_NAME_LEN];
+  char corrected_err_timed_period[DATA_MAX_NAME_LEN/2];
   int uncorrected_err_total; /* x total*/
   int uncorrected_err_timed; /* x in 24h*/
-  char uncorrected_err_timed_period[DATA_MAX_NAME_LEN];
-  char location[DATA_MAX_NAME_LEN];  /* SOCKET x CHANNEL x DIMM x*/
-  char dimm_name[DATA_MAX_NAME_LEN]; /* DMI_NAME "DIMM_F1" */
+  char uncorrected_err_timed_period[DATA_MAX_NAME_LEN/2];
+  char location[DATA_MAX_NAME_LEN/2];  /* SOCKET x CHANNEL x DIMM x*/
+  char dimm_name[DATA_MAX_NAME_LEN/2]; /* DMI_NAME "DIMM_F1" */
 } mcelog_memory_rec_t;
 
 static int socket_close(socket_adapter_t *self);
index 429e256dbf32369e57c4a2cb668807c5757de794..747bcc2228b935d0d9c508b2d416e159e9944690 100644 (file)
@@ -221,7 +221,8 @@ static int tn_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
     char template[DATA_MAX_NAME_LEN];
     char value_str[DATA_MAX_NAME_LEN];
 
-    snprintf(template, sizeof(template), "%%{ds:%s}", ds->ds[i].name);
+    const char *format = "%%{ds:%.*s}";
+    snprintf(template, sizeof(template), format, DATA_MAX_NAME_LEN - strlen(format), ds->ds[i].name);
 
     if (ds->ds[i].type != DS_TYPE_GAUGE) {
       if ((rates == NULL) && (rates_failed == 0)) {
index 65655dcd12b7b57aefb9070a87c242a394ecc898..50622092a5953bb18af06e5ea33f5598e04c699b 100644 (file)
@@ -118,7 +118,7 @@ static int latency_submit_match(cu_match_t *match, void *user_data) {
   sstrncpy(vl.type, data->type, sizeof(vl.type));
   for (size_t i = 0; i < data->latency_config.percentile_num; i++) {
     if (strlen(data->type_instance) != 0)
-      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f",
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%.117s-%.2f",
                data->type_instance, data->latency_config.percentile[i]);
     else
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%.0f",
@@ -150,10 +150,10 @@ static int latency_submit_match(cu_match_t *match, void *user_data) {
         bucket.upper_bound ? CDTIME_T_TO_DOUBLE(bucket.upper_bound) : INFINITY;
 
     if (strlen(data->type_instance) != 0)
-      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%.54s-%.54s-%.2g_%.2g",
                data->type, data->type_instance, lower_bound, upper_bound);
     else
-      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%.107s-%.2g_%.2g",
                data->type, lower_bound, upper_bound);
 
     vl.values = &(value_t){