]> arthur.barton.de Git - netdata.git/commitdiff
snprintfz must use a buffer 1 byte bigger then maximum string output size.
authorFrederico Lamberti Pissarra <fredericopissarra@gmail.com>
Mon, 9 May 2016 03:24:43 +0000 (00:24 -0300)
committerFrederico Lamberti Pissarra <fredericopissarra@gmail.com>
Mon, 9 May 2016 03:24:43 +0000 (00:24 -0300)
src/proc_interrupts.c
src/proc_softirqs.c

index 6704ef1a59ac966d52b742fb8b6e35d9fd907ce5..8264546cc7ef61cab0a85934d02e34ff0be16b81 100644 (file)
@@ -53,7 +53,7 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
 
        if(!ff) {
                char filename[FILENAME_MAX + 1];
-               snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/interrupts");
+               snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/interrupts");
                ff = procfile_open(config_get("plugin:proc:/proc/interrupts", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
        }
        if(!ff) return 1;
@@ -116,18 +116,15 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
                }
 
                if(isdigit(irr->id[0]) && (uint32_t)(cpus + 2) < words) {
-                       strncpy(irr->name, procfile_lineword(ff, l, words - 1), MAX_INTERRUPT_NAME);
-                       irr->name[MAX_INTERRUPT_NAME] = '\0';
+                       strncpyz(irr->name, procfile_lineword(ff, l, words - 1), MAX_INTERRUPT_NAME);
                        int nlen = strlen(irr->name);
                        if(nlen < (MAX_INTERRUPT_NAME-1)) {
                                irr->name[nlen] = '_';
-                               strncpy(&irr->name[nlen + 1], irr->id, MAX_INTERRUPT_NAME - nlen);
-                               irr->name[MAX_INTERRUPT_NAME] = '\0';
+                               strncpyz(&irr->name[nlen + 1], irr->id, MAX_INTERRUPT_NAME - nlen);
                        }
                }
                else {
-                       strncpy(irr->name, irr->id, MAX_INTERRUPT_NAME);
-                       irr->name[MAX_INTERRUPT_NAME] = '\0';
+                       strncpyz(irr->name, irr->id, MAX_INTERRUPT_NAME);
                }
 
                irr->used = 1;
@@ -158,14 +155,14 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
                int c;
 
                for(c = 0; c < cpus ; c++) {
-                       char id[256];
-                       snprintf(id, 256, "cpu%d_interrupts", c);
+                       char id[256+1];
+                       snprintfz(id, 256, "cpu%d_interrupts", c);
 
                        st = rrdset_find_bytype("cpu", id);
                        if(!st) {
-                               char name[256], title[256];
-                               snprintf(name, 256, "cpu%d_interrupts", c);
-                               snprintf(title, 256, "CPU%d Interrupts", c);
+                               char name[256+1], title[256+1];
+                               snprintfz(name, 256, "cpu%d_interrupts", c);
+                               snprintfz(title, 256, "CPU%d Interrupts", c);
                                st = rrdset_create("cpu", id, name, "interrupts", "cpu.interrupts", title, "interrupts/s", 2000 + c, update_every, RRDSET_TYPE_STACKED);
 
                                for(l = 0; l < lines ;l++) {
index c3a75f600abe0893f3b6393b2265c0b1fbf29ee5..f350a54dc08c0fd5c140883b6e17c9f8efe0f20d 100644 (file)
@@ -53,7 +53,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
 
        if(!ff) {
                char filename[FILENAME_MAX + 1];
-               snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/softirqs");
+               snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/softirqs");
                ff = procfile_open(config_get("plugin:proc:/proc/softirqs", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
        }
        if(!ff) return 1;
@@ -115,8 +115,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
                        irr->total += irr->value[c];
                }
 
-               strncpy(irr->name, irr->id, MAX_INTERRUPT_NAME);
-               irr->name[MAX_INTERRUPT_NAME] = '\0';
+               strncpyz(irr->name, irr->id, MAX_INTERRUPT_NAME);
 
                irr->used = 1;
        }
@@ -146,8 +145,8 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
                int c;
 
                for(c = 0; c < cpus ; c++) {
-                       char id[256];
-                       snprintf(id, 256, "cpu%d_softirqs", c);
+                       char id[256+1];
+                       snprintfz(id, 256, "cpu%d_softirqs", c);
 
                        st = rrdset_find_bytype("cpu", id);
                        if(!st) {
@@ -159,9 +158,9 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
                                }
                                if(core_sum == 0) continue; // try next core
 
-                               char name[256], title[256];
-                               snprintf(name, 256, "cpu%d_softirqs", c);
-                               snprintf(title, 256, "CPU%d softirqs", c);
+                               char name[256+1], title[256+1];
+                               snprintfz(name, 256, "cpu%d_softirqs", c);
+                               snprintfz(title, 256, "CPU%d softirqs", c);
                                st = rrdset_create("cpu", id, name, "softirqs", "cpu.softirqs", title, "softirqs/s", 3000 + c, update_every, RRDSET_TYPE_STACKED);
 
                                for(l = 0; l < lines ;l++) {