Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/catman readlink(3) does not terminate string by \0.



details:   https://anonhg.NetBSD.org/src/rev/9ea435a681ab
branches:  trunk
changeset: 546925:9ea435a681ab
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri May 09 00:43:46 2003 +0000

description:
readlink(3) does not terminate string by \0.

diffstat:

 usr.sbin/catman/catman.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (34 lines):

diff -r e32c049134d5 -r 9ea435a681ab usr.sbin/catman/catman.c
--- a/usr.sbin/catman/catman.c  Fri May 09 00:16:55 2003 +0000
+++ b/usr.sbin/catman/catman.c  Fri May 09 00:43:46 2003 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: catman.c,v 1.19 2002/10/19 20:33:19 provos Exp $       */
+/*      $NetBSD: catman.c,v 1.20 2003/05/09 00:43:46 itojun Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -297,9 +297,10 @@
                                        }
                                } else {
                                        len = readlink(manpaths.gl_pathv[i],
-                                                       path, PATH_MAX - 1);
+                                                       path, sizeof(path) - 1);
                                        if (len == -1)
                                                continue;
+                                       path[len] = '\0';
                                        if (!strcmp(path, manpaths.gl_pathv[j]))
                                                lnk = 1;
                                }
@@ -413,8 +414,10 @@
                        if(S_ISLNK(manstat.st_mode)) {
                                strcpy(buffer, catpage);
                                strcpy(linkname, basename(buffer));
-                               len = readlink(manpage, buffer, PATH_MAX);
-                               if(len == -1) {
+                               len = readlink(manpage, buffer,
+                                   sizeof(buffer) - 1);
+                               buffer[PATH_MAX - 1] = '\0';
+                               if (len == -1) {
                                        warn("can't stat read symbolic link %s",
                                                        manpage);
                                        continue;



Home | Main Index | Thread Index | Old Index