#include <signal.h>
#include <unistd.h>
#include <inttypes.h>
+#include <limits.h>
#include "resource-monitor.h"
};
struct resource_monitor_data {
- unsigned int secs;
- unsigned int max;
+ int secs;
+ int max;
int mon_id;
int num_res;
int ret = 0;
int length;
double *array = NULL;
- char buf[BUFF_MAX];
- char temp[10];
+ char buf[BUFF_MAX + 1];
+ char temp[BUFF_MAX];
if (!res)
return -1;
if (ret < 0) break;
- memset(buf, 0, BUFF_MAX);
+ memset(buf, 0, BUFF_MAX + 1);
for (i = 0; i < length; i++) {
- snprintf(temp, 10, "%2.2f ", array[i]);
- strcat(buf, temp);
+ snprintf(temp, BUFF_MAX, "%2.2f ", array[i]);
+
+ if (strlen(buf) + strlen(temp) >= BUFF_MAX)
+ break;
+
+ strncat(buf, temp, BUFF_MAX);
}
printf("%40s | %-5s | %s", buf, res->attrs[idx].unit, res->attrs[idx].desc);
while (opt < argc) {
if (!strncmp(argv[opt], "-", 1)) {
for (i = 1; *(argv[opt] + i); i++) {
+ int input;
+
switch (*(argv[opt] + i)) {
case 'd':
- g_data.secs = atoi(argv[opt + 1]);
+ input = atoi(argv[opt + 1]);
+ if (input < 0 || input >= INT_MAX)
+ break;
+ g_data.secs = input;
break;
case 'n':
- g_data.max = atoi(argv[opt + 1]);
+ input = atoi(argv[opt + 1]);
+ if (input < 0 || input >= INT_MAX)
+ break;
+ g_data.max = input;
break;
case 'h':
usage();