1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

Don't crash when using out-of-range cpu numbers (sf.net #3368243)

bug reported by Ormaaj
This commit is contained in:
Pavel Labath 2011-10-02 19:16:29 +02:00
parent 422cc24ba2
commit b3d96b3b34
2 changed files with 13 additions and 7 deletions

View File

@ -902,12 +902,17 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(cpu) { OBJ(cpu) {
if (cur->cpu_usage) { if (cur->cpu_usage) {
if (obj->data.i > info.cpu_count) { if (obj->data.i > info.cpu_count) {
NORM_ERR("obj->data.i %i info.cpu_count %i", static bool warned = false;
obj->data.i, info.cpu_count); if(!warned) {
CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!"); NORM_ERR("obj->data.i %i info.cpu_count %i",
} obj->data.i, info.cpu_count);
percent_print(p, p_max_size, NORM_ERR("attempting to use more CPUs than you have!");
warned = true;
}
} else {
percent_print(p, p_max_size,
round_to_int(cur->cpu_usage[obj->data.i] * 100.0)); round_to_int(cur->cpu_usage[obj->data.i] * 100.0));
}
} }
} }
OBJ(cpugauge) OBJ(cpugauge)

View File

@ -927,8 +927,9 @@ static int open_sysfs_sensor(const char *dir, const char *dev, const char *type,
snprintf(path, 255, "%s%s/%s%d_input", dir, dev, type, n); snprintf(path, 255, "%s%s/%s%d_input", dir, dev, type, n);
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nplease check your device or remove this " NORM_ERR("can't open '%s': %s\nplease check your device or remove this "
"var from "PACKAGE_NAME, path, strerror(errno)); "var from "PACKAGE_NAME, path, strerror(errno));
return -1;
} }
} }
@ -1080,7 +1081,7 @@ void print_sysfs_sensor(struct text_object *obj, char *p, int p_max_size)
double r; double r;
struct sysfs *sf = obj->data.opaque; struct sysfs *sf = obj->data.opaque;
if (!sf) if (!sf || sf->fd < 0)
return; return;
r = get_sysfs_info(&sf->fd, sf->arg, r = get_sysfs_info(&sf->fd, sf->arg,