Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit - fix memory allocation botch in wide strings



details:   https://anonhg.NetBSD.org/src/rev/4416fae6f46e
branches:  trunk
changeset: 767703:4416fae6f46e
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jul 28 00:48:21 2011 +0000

description:
- fix memory allocation botch in wide strings
- check mbstowcs return code

diffstat:

 lib/libedit/chartype.c |  12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diffs (47 lines):

diff -r 786800014b37 -r 4416fae6f46e lib/libedit/chartype.c
--- a/lib/libedit/chartype.c    Thu Jul 28 00:45:50 2011 +0000
+++ b/lib/libedit/chartype.c    Thu Jul 28 00:48:21 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.c,v 1.5 2011/07/27 02:18:30 christos Exp $    */
+/*     $NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $    */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.5 2011/07/27 02:18:30 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $");
 #endif /* not lint && not SCCSID */
 #include "el.h"
 #include <stdlib.h>
@@ -52,7 +52,7 @@
        void *p;
        if (mincsize > conv->csize) {
                conv->csize = mincsize;
-               p = el_realloc(conv->cbuff, conv->csize);
+               p = el_realloc(conv->cbuff, conv->csize * sizeof(char));
                if (p == NULL) {
                        conv->csize = 0;
                        el_free(conv->cbuff);
@@ -63,7 +63,7 @@
 
        if (minwsize > conv->wsize) {
                conv->wsize = minwsize;
-               p = el_realloc(conv->wbuff, conv->wsize);
+               p = el_realloc(conv->wbuff, conv->wsize * sizeof(Char));
                if (p == NULL) {
                        conv->wsize = 0;
                        el_free(conv->wbuff);
@@ -119,7 +119,9 @@
        if (!conv->wbuff)
                return NULL;
 
-       len = ct_mbstowcs(0, s, 0);
+       len = ct_mbstowcs(NULL, s, 0);
+       if (len == (size_t)-1)
+               return NULL;
        if (len > conv->wsize)
                ct_conv_buff_resize(conv, 0, len + 1);
        if (!conv->wbuff)



Home | Main Index | Thread Index | Old Index