Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdio Handle errors from getdelim better.



details:   https://anonhg.NetBSD.org/src/rev/2dcedd1b46a6
branches:  trunk
changeset: 748164:2dcedd1b46a6
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Oct 15 00:36:24 2009 +0000

description:
Handle errors from getdelim better.

diffstat:

 lib/libc/stdio/fgetstr.c |  10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diffs (38 lines):

diff -r aeffe9a67c9f -r 2dcedd1b46a6 lib/libc/stdio/fgetstr.c
--- a/lib/libc/stdio/fgetstr.c  Thu Oct 15 00:34:05 2009 +0000
+++ b/lib/libc/stdio/fgetstr.c  Thu Oct 15 00:36:24 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fgetstr.c,v 1.7 2009/10/14 20:54:51 roy Exp $      */
+/* $NetBSD: fgetstr.c,v 1.8 2009/10/15 00:36:24 roy Exp $      */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fgetstr.c,v 1.7 2009/10/14 20:54:51 roy Exp $");
+__RCSID("$NetBSD: fgetstr.c,v 1.8 2009/10/15 00:36:24 roy Exp $");
 
 #include "namespace.h"
 
@@ -58,17 +58,15 @@
        p = (char *)fp->_lb._base;
        size = fp->_lb._size;
        *lenp = __getdelim(&p, &size, sep, fp);
+       fp->_lb._base = (unsigned char *)p;
        /* The struct size variable is only an int ..... */
        if (size > INT_MAX) {
                fp->_lb._size = INT_MAX;
                errno = EOVERFLOW;
                goto error;
        }
-       fp->_lb._base = (unsigned char *)p;
        fp->_lb._size = (int)size;
-       if (*lenp == 0)
-               return NULL;
-       if (*lenp < SIZE_MAX)
+       if (*lenp != 0 && *lenp < SIZE_MAX - 1)
                return p;
 error:
        *lenp = 0;



Home | Main Index | Thread Index | Old Index