snprintfz must use a buffer 1 byte bigger then maximum string output size.
Frederico Lamberti Pissarra committed
May 9, 2016 at 00:24 UTC
127f5be926c6980876b66a7d96cd8dd795153a7a
2 files changed
+16
-20
src/proc_interrupts.c
+9
-12
@@ -53,7 +53,7 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
53
54
if(!ff) {
55
char filename[FILENAME_MAX + 1];
56
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/interrupts");
56
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/interrupts");
57
ff = procfile_open(config_get("plugin:proc:/proc/interrupts", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
58
}
59
if(!ff) return 1;
@@ -116,18 +116,15 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
116
}
117
118
if(isdigit(irr->id[0]) && (uint32_t)(cpus + 2) < words) {
119
- strncpy(irr->name, procfile_lineword(ff, l, words - 1), MAX_INTERRUPT_NAME);
120
- irr->name[MAX_INTERRUPT_NAME] = '\0';
119
+ strncpyz(irr->name, procfile_lineword(ff, l, words - 1), MAX_INTERRUPT_NAME);
120
int nlen = strlen(irr->name);
121
if(nlen < (MAX_INTERRUPT_NAME-1)) {
122
irr->name[nlen] = '_';
124
- strncpy(&irr->name[nlen + 1], irr->id, MAX_INTERRUPT_NAME - nlen);
125
- irr->name[MAX_INTERRUPT_NAME] = '\0';
123
+ strncpyz(&irr->name[nlen + 1], irr->id, MAX_INTERRUPT_NAME - nlen);
124
}
125
}
126
else {
129
- strncpy(irr->name, irr->id, MAX_INTERRUPT_NAME);
130
- irr->name[MAX_INTERRUPT_NAME] = '\0';
127
+ strncpyz(irr->name, irr->id, MAX_INTERRUPT_NAME);
128
}
129
130
irr->used = 1;
@@ -158,14 +155,14 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
155
int c;
156
157
for(c = 0; c < cpus ; c++) {
161
- char id[256];
162
- snprintf(id, 256, "cpu%d_interrupts", c);
158
+ char id[256+1];
159
+ snprintfz(id, 256, "cpu%d_interrupts", c);
160
161
st = rrdset_find_bytype("cpu", id);
162
if(!st) {
166
- char name[256], title[256];
167
- snprintf(name, 256, "cpu%d_interrupts", c);
168
- snprintf(title, 256, "CPU%d Interrupts", c);
163
+ char name[256+1], title[256+1];
164
+ snprintfz(name, 256, "cpu%d_interrupts", c);
165
+ snprintfz(title, 256, "CPU%d Interrupts", c);
166
st = rrdset_create("cpu", id, name, "interrupts", "cpu.interrupts", title, "interrupts/s", 2000 + c, update_every, RRDSET_TYPE_STACKED);
167
168
for(l = 0; l < lines ;l++) {
src/proc_softirqs.c
+7
-8
@@ -53,7 +53,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
53
54
if(!ff) {
55
char filename[FILENAME_MAX + 1];
56
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/softirqs");
56
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/softirqs");
57
ff = procfile_open(config_get("plugin:proc:/proc/softirqs", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
58
}
59
if(!ff) return 1;
@@ -115,8 +115,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
115
irr->total += irr->value[c];
116
}
117
118
- strncpy(irr->name, irr->id, MAX_INTERRUPT_NAME);
119
- irr->name[MAX_INTERRUPT_NAME] = '\0';
118
+ strncpyz(irr->name, irr->id, MAX_INTERRUPT_NAME);
119
120
irr->used = 1;
121
}
@@ -146,8 +145,8 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
145
int c;
146
147
for(c = 0; c < cpus ; c++) {
149
- char id[256];
150
- snprintf(id, 256, "cpu%d_softirqs", c);
148
+ char id[256+1];
149
+ snprintfz(id, 256, "cpu%d_softirqs", c);
150
151
st = rrdset_find_bytype("cpu", id);
152
if(!st) {
@@ -159,9 +158,9 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
158
}
159
if(core_sum == 0) continue; // try next core
160
162
- char name[256], title[256];
163
- snprintf(name, 256, "cpu%d_softirqs", c);
164
- snprintf(title, 256, "CPU%d softirqs", c);
161
+ char name[256+1], title[256+1];
162
+ snprintfz(name, 256, "cpu%d_softirqs", c);
163
+ snprintfz(title, 256, "CPU%d softirqs", c);
164
st = rrdset_create("cpu", id, name, "softirqs", "cpu.softirqs", title, "softirqs/s", 3000 + c, update_every, RRDSET_TYPE_STACKED);
165
166
for(l = 0; l < lines ;l++) {