]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
aklog: Fix improper use of readlink
authorSimon Wilkinson <sxw@your-file-system.com>
Sat, 2 Mar 2013 09:16:10 +0000 (09:16 +0000)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 7 Mar 2013 15:51:14 +0000 (07:51 -0800)
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 <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
src/aklog/aklog.c

index 6e096b0d13ad5205100b22495835c8ede36db2b2..22df70d277d62259e1d6a14b42c314f2519551f4 100644 (file)
@@ -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);