Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Deal with traps that reset the (same) trap in the tra...



details:   https://anonhg.NetBSD.org/src/rev/fd996a8a63a1
branches:  trunk
changeset: 823575:fd996a8a63a1
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Apr 26 22:41:53 2017 +0000

description:
Deal with traps that reset the (same) trap in the trap handler
(avoid referrencing memory that might have been freed).
>From FreeBSD (ages ago, just not committed until now...)

diffstat:

 bin/sh/trap.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (37 lines):

diff -r 93ff5f8965b6 -r fd996a8a63a1 bin/sh/trap.c
--- a/bin/sh/trap.c     Wed Apr 26 21:03:52 2017 +0000
+++ b/bin/sh/trap.c     Wed Apr 26 22:41:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.37 2015/08/22 12:12:47 christos Exp $       */
+/*     $NetBSD: trap.c,v 1.38 2017/04/26 22:41:53 kre Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)trap.c     8.5 (Berkeley) 6/5/95";
 #else
-__RCSID("$NetBSD: trap.c,v 1.37 2015/08/22 12:12:47 christos Exp $");
+__RCSID("$NetBSD: trap.c,v 1.38 2017/04/26 22:41:53 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -404,6 +404,7 @@
 {
        int i;
        int savestatus;
+       char *tr;
 
        for (;;) {
                for (i = 1 ; ; i++) {
@@ -414,7 +415,9 @@
                }
                gotsig[i - 1] = 0;
                savestatus=exitstatus;
-               evalstring(trap[i], 0);
+               tr = savestr(trap[i]);          /* trap code may free trap[i] */
+               evalstring(tr, 0);
+               ckfree(tr);
                exitstatus=savestatus;
        }
 done:



Home | Main Index | Thread Index | Old Index