Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit Add NULL check after doing memory allocation at ...



details:   https://anonhg.NetBSD.org/src/rev/3ed0d8b3783b
branches:  trunk
changeset: 827418:3ed0d8b3783b
user:      abhinav <abhinav%NetBSD.org@localhost>
date:      Fri Oct 27 18:16:09 2017 +0000

description:
Add NULL check after doing memory allocation at a couple of places

ok christos@

diffstat:

 lib/libedit/filecomplete.c |  10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diffs (45 lines):

diff -r 264bf0f8361b -r 3ed0d8b3783b lib/libedit/filecomplete.c
--- a/lib/libedit/filecomplete.c        Fri Oct 27 12:25:14 2017 +0000
+++ b/lib/libedit/filecomplete.c        Fri Oct 27 18:16:09 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filecomplete.c,v 1.47 2017/10/15 18:59:00 abhinav Exp $        */
+/*     $NetBSD: filecomplete.c,v 1.48 2017/10/27 18:16:09 abhinav Exp $        */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.47 2017/10/15 18:59:00 abhinav Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.48 2017/10/27 18:16:09 abhinav Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -576,6 +576,8 @@
 
        len = (size_t)(li->cursor - ctemp);
        temp = el_malloc((len + 1) * sizeof(*temp));
+       if (temp == NULL)
+               goto out;
        (void)wcsncpy(temp, ctemp, len);
        temp[len] = '\0';
 
@@ -618,6 +620,8 @@
                                 * object is a directory. Also do necessary escape quoting
                                 */
                                char *escaped_completion = escape_filename(el, matches[0]);
+                               if (escaped_completion == NULL)
+                                       goto out;
                                el_winsertstr(el,
                                        ct_decode_string(escaped_completion, &el->el_scratch));
                                el_winsertstr(el,
@@ -698,6 +702,8 @@
                el_free(matches);
                matches = NULL;
        }
+
+out:
        el_free(temp);
        return retval;
 }



Home | Main Index | Thread Index | Old Index