Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen From Brian Ginsbach: Fix overflow detection, an...



details:   https://anonhg.NetBSD.org/src/rev/dfc97c45756a
branches:  trunk
changeset: 515181:dfc97c45756a
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Sep 18 16:37:26 2001 +0000

description:
>From Brian Ginsbach: Fix overflow detection, and only abort on long paths
when GLOB_ERR is set.

diffstat:

 lib/libc/gen/__glob13.c |  26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diffs (49 lines):

diff -r 4d80f955d6c2 -r dfc97c45756a lib/libc/gen/__glob13.c
--- a/lib/libc/gen/__glob13.c   Tue Sep 18 16:24:16 2001 +0000
+++ b/lib/libc/gen/__glob13.c   Tue Sep 18 16:37:26 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: __glob13.c,v 1.22 2001/09/08 22:39:21 christos Exp $   */
+/*     $NetBSD: __glob13.c,v 1.23 2001/09/18 16:37:26 christos Exp $   */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)glob.c     8.3 (Berkeley) 10/13/93";
 #else
-__RCSID("$NetBSD: __glob13.c,v 1.22 2001/09/08 22:39:21 christos Exp $");
+__RCSID("$NetBSD: __glob13.c,v 1.23 2001/09/18 16:37:26 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -730,12 +730,26 @@
                for (sc = (u_char *) dp->d_name, dc = pathend; 
                     dc <= pathlim && (*dc++ = *sc++) != EOS;)
                        continue;
+
                /*
-                * we compare to one after pathlim, since the pointer
-                * has been post-incremented.
+                * Have we filled the buffer without seeing EOS?
                 */
-               if (dc > pathlim + 1)
-                       return GLOB_ABORTED;
+               if (dc > pathlim && *pathlim != EOS) {
+                       /*
+                        * Abort when requested by caller, otherwise
+                        * reset pathend back to last SEP and continue
+                        * with next dir entry.
+                        */
+                       if (pglob->gl_flags & GLOB_ERR) {
+                               error = GLOB_ABORTED;
+                               break;
+                       }
+                       else {
+                               *pathend = EOS;
+                               continue;
+                       }
+               }
+
                if (!match(pathend, pattern, restpattern)) {
                        *pathend = EOS;
                        continue;



Home | Main Index | Thread Index | Old Index