meminfo-writer: ensure we do not write outside our buffer
Reading the max size would cause a NUL to be written after the buffer, while an error would cause one to be written before it.
This commit is contained in:
parent
2758d2a1d3
commit
e6c29bbae1
@ -163,17 +163,31 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
/* if not waiting for signal, fork after first info written to xenstore */
|
/* if not waiting for signal, fork after first info written to xenstore */
|
||||||
n = pread(fd, buf, sizeof(buf), 0);
|
n = pread(fd, buf, sizeof(buf)-1, 0);
|
||||||
|
if (n < 0) {
|
||||||
|
perror("pread");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
meminfo_data = parse(buf);
|
meminfo_data = parse(buf);
|
||||||
if (meminfo_data)
|
if (meminfo_data)
|
||||||
send_to_qmemman(xs, meminfo_data);
|
send_to_qmemman(xs, meminfo_data);
|
||||||
if (fork() > 0)
|
n = fork();
|
||||||
|
if (n < 0) {
|
||||||
|
perror("fork");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (n > 0)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
usleep(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
n = pread(fd, buf, sizeof(buf), 0);
|
n = pread(fd, buf, sizeof(buf)-1, 0);
|
||||||
|
if (n < 0) {
|
||||||
|
perror("pread");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
meminfo_data = parse(buf);
|
meminfo_data = parse(buf);
|
||||||
if (meminfo_data)
|
if (meminfo_data)
|
||||||
|
Loading…
Reference in New Issue
Block a user