qubes-restore: properly NUL terminate buffer and check for errors
It looks like a succesful read would have worked, assuming that the other side always sends a \n last, as strtoul would find one before the NUL. However, an error would write before the buffer.
This commit is contained in:
parent
bba989e0a6
commit
bf6486e973
@ -13,7 +13,7 @@
|
|||||||
#include <xs.h>
|
#include <xs.h>
|
||||||
|
|
||||||
int restore_domain(char *restore_file, char *conf_file, char *name) {
|
int restore_domain(char *restore_file, char *conf_file, char *name) {
|
||||||
int pid, status, domid;
|
int pid, status, domid, ret;
|
||||||
int pipe_fd[2];
|
int pipe_fd[2];
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char *endptr;
|
char *endptr;
|
||||||
@ -61,8 +61,12 @@ int restore_domain(char *restore_file, char *conf_file, char *name) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
read(pipe_fd[0], buf, sizeof(buf)-1);
|
ret = read(pipe_fd[0], buf, sizeof(buf)-1);
|
||||||
buf[sizeof(buf)-1] = 0;
|
if (ret < 0) {
|
||||||
|
perror("read");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
buf[ret] = 0;
|
||||||
domid = strtoul(buf, &endptr, 10);
|
domid = strtoul(buf, &endptr, 10);
|
||||||
if (domid <= 0 || *endptr != '\n') {
|
if (domid <= 0 || *endptr != '\n') {
|
||||||
fprintf(stderr, "Cannot get DispVM xid\n");
|
fprintf(stderr, "Cannot get DispVM xid\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user