1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-14 11:33:14 +00:00

Make sure char-arrays filled with read() are null-terminated

This commit is contained in:
Nikolas Garofil 2010-11-23 17:33:26 +01:00
parent a8d633009d
commit c1933dc186
2 changed files with 6 additions and 8 deletions

View File

@ -1988,7 +1988,7 @@ static void main_loop(void)
#ifdef HAVE_SYS_INOTIFY_H
int inotify_config_wd = -1;
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
#define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
#define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16)) + 1
char inotify_buff[INOTIFY_BUF_LEN];
#endif /* HAVE_SYS_INOTIFY_H */
@ -2408,7 +2408,7 @@ static void main_loop(void)
select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
if (FD_ISSET(inotify_fd, &descriptors)) {
/* process inotify events */
len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN - 1);
while (len > 0 && idx < len) {
struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {

View File

@ -2454,7 +2454,7 @@ static unsigned long long calc_cpu_total(void)
KFLAG_ISSET(KFLAG_IS_LONGSTAT) ? TMPL_LONGPROC : TMPL_SHORTPROC;
ps = open("/proc/stat", O_RDONLY);
rc = read(ps, line, sizeof(line));
rc = read(ps, line, BUFFER_LEN - 1);
close(ps);
if (rc < 0) {
return 0;
@ -2535,7 +2535,7 @@ static void process_parse_stat(struct process *process)
/* Mark process as up-to-date. */
process->time_stamp = g_time;
rc = read(ps, line, sizeof(line));
rc = read(ps, line, BUFFER_LEN - 1);
close(ps);
if (rc < 0) {
return;
@ -2572,11 +2572,9 @@ static void process_parse_stat(struct process *process)
return;
}
endl = read(ps, line, sizeof(line));
endl = read(ps, line, BUFFER_LEN - 1);
close(ps);
/* null terminate the input */
line[endl] = 0;
/* account for "kdeinit: " */
if ((char *) line == strstr(line, "kdeinit: ")) {
r = ((char *) line) + 9;
@ -2647,7 +2645,7 @@ static void process_parse_io(struct process *process)
return;
}
rc = read(ps, line, sizeof(line));
rc = read(ps, line, BUFFER_LEN - 1);
close(ps);
if (rc < 0) {
return;