res->mon_id, res->res_id,
res->attrs[idx].id, &array, &length);
- if (ret < 0) break;
+ /*
+ * Since each array item is represented with %2.2f, they
+ * occupy 4bytes each at least, for instance, x.xx. So,
+ * if length is larger than BUFF_MAX/4, it will obviously
+ * be failed to store in 'buf' and there is no need to proceed.
+ */
+ if (ret < 0 || length < 0 || length > (BUFF_MAX / 4))
+ break;
memset(buf, 0, BUFF_MAX + 1);
for (i = 0; i < length; i++) {
/* 1. Initialize resource-monitor */
id = resource_monitor_init();
+ if (id < 0)
+ return id;
g_data.mon_id = id;
/* 2. Get resource count */