NUL terminate the readlink buffer
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 30 Aug 1989 07:58:06 +0000 (23:58 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 30 Aug 1989 07:58:06 +0000 (23:58 -0800)
SCCS-vsn: bin/cp/cp.c 5.9

usr/src/bin/cp/cp.c

index 7a71b65..09075cf 100644 (file)
@@ -25,7 +25,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)cp.c       5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)cp.c       5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -405,12 +405,14 @@ done:             dir_list[i] = NULL;
 copy_link(exists)
        int exists;
 {
 copy_link(exists)
        int exists;
 {
+       int len;
        char link[MAXPATHLEN];
 
        char link[MAXPATHLEN];
 
-       if (readlink(from.p_path, link, sizeof(link)) == -1) {
+       if ((len = readlink(from.p_path, link, sizeof(link))) == -1) {
                error(from.p_path);
                return;
        }
                error(from.p_path);
                return;
        }
+       link[len] = '\0';
        if (exists && unlink(to.p_path)) {
                error(to.p_path);
                return;
        if (exists && unlink(to.p_path)) {
                error(to.p_path);
                return;