Source-Changes-HG archive

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

[src/trunk]: src/lib/libmenu Allocate private string buffers for the menu mar...



details:   https://anonhg.NetBSD.org/src/rev/90b836f380e1
branches:  trunk
changeset: 535450:90b836f380e1
user:      blymn <blymn%NetBSD.org@localhost>
date:      Mon Aug 19 11:01:11 2002 +0000

description:
Allocate private string buffers for the menu mark and unmark to prevent
a double free of the string memory.  This fixes PR 17937.

diffstat:

 lib/libmenu/menu.c |  33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diffs (51 lines):

diff -r 9d839924d1b4 -r 90b836f380e1 lib/libmenu/menu.c
--- a/lib/libmenu/menu.c        Mon Aug 19 10:16:51 2002 +0000
+++ b/lib/libmenu/menu.c        Mon Aug 19 11:01:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: menu.c,v 1.12 2002/07/29 13:03:51 blymn Exp $  */
+/*     $NetBSD: menu.c,v 1.13 2002/08/19 11:01:11 blymn Exp $  */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn (blymn%baea.com.au@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -455,10 +455,41 @@
          /* set a default window if none already set. */
        if (the_menu->menu_win == NULL)
                the_menu->scrwin = stdscr;
+
+         /* make a private copy of the mark string */
+       if (_menui_default_menu.mark.string != NULL) {
+               if ((the_menu->mark.string =
+                    (char *) malloc((unsigned) _menui_default_menu.mark.length + 1))
+                   == NULL) {
+                       free(the_menu);
+                       return NULL;
+               }
+
+               strlcpy(the_menu->mark.string, _menui_default_menu.mark.string,
+                       (unsigned) _menui_default_menu.mark.length);
+       }
        
+         /* make a private copy of the unmark string too */
+       if (_menui_default_menu.unmark.string != NULL) {
+               if ((the_menu->unmark.string =
+                    (char *) malloc((unsigned) _menui_default_menu.unmark.length + 1))
+                   == NULL) {
+                       free(the_menu);
+                       return NULL;
+               }
+
+               strlcpy(the_menu->unmark.string,
+                       _menui_default_menu.unmark.string,
+                       (unsigned) _menui_default_menu.unmark.length);
+       }
+
           /* now attach the items, if any */
         if (items != NULL) {
                if(set_menu_items(the_menu, items) < 0) {
+                       if (the_menu->mark.string != NULL)
+                               free(the_menu->mark.string);
+                       if (the_menu->unmark.string != NULL)
+                               free(the_menu->unmark.string);
                        free(the_menu);
                        return NULL;
                }



Home | Main Index | Thread Index | Old Index