Hi,

On Thu, 1 Aug 2019 18:02:41 +0200
Ingo Schwarze <[email protected]> wrote:
> YASUOKA Masahiko wrote on Thu, Aug 01, 2019 at 08:42:35PM +0900:
>> I noticed the upstream NetBSD recently replaced almost all malloc(3)s
>> by calloc(3) in libedit.
>> 
>> https://github.com/NetBSD/src/commit/b91b3c48e0edb116bd797586430cb426b575d717
>> 
>> This also fixes the problem.  I'll create a diff which does the same
>> thing.
> 
> Might i suggest that you first send a diff changing only the one place
> required to fix the bug asou@ reported?  That can easily be reviewed,
> and i expect we can get it in quickly, and it allows a useful commit
> message explaining why exactly it is needed.

This is the diff which fixes the problem by replacing malloc by calloc.

ok?

Initialize the line buffer by zero when allocation.  This fixes the
problem a crash happens after the window size change.

Index: lib/libedit/terminal.c
===================================================================
RCS file: /cvs/src/lib/libedit/terminal.c,v
retrieving revision 1.18
diff -u -p -r1.18 terminal.c
--- lib/libedit/terminal.c      12 Apr 2017 18:24:37 -0000      1.18
+++ lib/libedit/terminal.c      5 Aug 2019 07:13:08 -0000
@@ -413,11 +413,11 @@ terminal_alloc_display(EditLine *el)
        wchar_t **b;
        coord_t *c = &el->el_terminal.t_size;
 
-       b = reallocarray(NULL, c->v + 1, sizeof(*b));
+       b = calloc(c->v + 1, sizeof(*b));
        if (b == NULL)
                goto done;
        for (i = 0; i < c->v; i++) {
-               b[i] = reallocarray(NULL, c->h + 1, sizeof(**b));
+               b[i] = calloc(c->h + 1, sizeof(**b));
                if (b[i] == NULL) {
                        while (--i >= 0)
                                free(b[i]);
@@ -428,11 +428,11 @@ terminal_alloc_display(EditLine *el)
        b[c->v] = NULL;
        el->el_display = b;
 
-       b = reallocarray(NULL, c->v + 1, sizeof(*b));
+       b = calloc(c->v + 1, sizeof(*b));
        if (b == NULL)
                goto done;
        for (i = 0; i < c->v; i++) {
-               b[i] = reallocarray(NULL, c->h + 1, sizeof(**b));
+               b[i] = calloc(c->h + 1, sizeof(**b));
                if (b[i] == NULL) {
                        while (--i >= 0)
                                free(b[i]);

Reply via email to