From: Simon Wilkinson Date: Sat, 2 Mar 2013 09:16:10 +0000 (+0000) Subject: aklog: Fix improper use of readlink X-Git-Tag: openafs-stable-1_8_0pre1~1357 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=2fac53522e7ef5b3a376e191bffdc1f6784e6995;hp=6a54bf735871d93bc77e5cf166e506f4f2423d0a aklog: Fix improper use of readlink readlink doesn't NUL terminate its return string, so it is up to us to do so. Caught by coverity (#985739) Change-Id: Ifb858d628845bd963928e25834e540bbb3a187c8 Reviewed-on: http://gerrit.openafs.org/9347 Reviewed-by: Derrick Brashear Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- diff --git a/src/aklog/aklog.c b/src/aklog/aklog.c index 6e096b0..22df70d 100644 --- a/src/aklog/aklog.c +++ b/src/aklog/aklog.c @@ -1192,12 +1192,16 @@ next_path(char *origpath) ? elast_comp - last_comp : strlen(last_comp); strncat(pathtocheck, last_comp, len); memset(linkbuf, 0, sizeof(linkbuf)); - if ((link = (readlink(pathtocheck, linkbuf, - sizeof(linkbuf)) > 0))) { + link = readlink(pathtocheck, linkbuf, sizeof(linkbuf)-1); + + if (link > 0) { + linkbuf[link] = '\0'; /* NUL terminate string */ + if (++symlinkcount > MAXSYMLINKS) { fprintf(stderr, "%s: %s\n", progname, strerror(ELOOP)); exit(AKLOG_BADPATH); } + memset(tmpbuf, 0, sizeof(tmpbuf)); if (elast_comp) strcpy(tmpbuf, elast_comp);