From b14f68378ddfbbb491f6ca0fceac9e805bcc608c Mon Sep 17 00:00:00 2001 From: Gao feng Date: Sat, 10 Oct 2015 18:00:55 +0800 Subject: [PATCH] fix incorrect path of link file Signed-off-by: Gao feng --- src/net.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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; }