diff --git a/src/net.c b/src/net.c index 4ece161..378f59e 100644 --- a/src/net.c +++ b/src/net.c @@ -335,14 +335,17 @@ static int hyper_remove_nic(char *device) { char path[256], real[128]; int fd; + ssize_t size; sprintf(path, "/sys/class/net/%s", device); - if (readlink(path, real, 128) < 0) { + size = readlink(path, real, 128); + if (size < 0 || size > 127) { perror("fail to read link directory"); return -1; } + real[size] = '\0'; sprintf(path, "/sys/%s/../../../remove", real + 5); fprintf(stdout, "get net sys path %s\n", path); @@ -869,7 +872,7 @@ void hyper_cleanup_dns(struct hyper_pod *pod) int fd = open("/tmp/hyper/resolv.conf", O_WRONLY| O_TRUNC); if (fd < 0) { - perror("open /tmp/resolv.conf failed"); + perror("open /tmp/hyper/resolv.conf failed"); return; }