Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/tprof use malloc instead of alloca so that SSP works.



details:   https://anonhg.NetBSD.org/src/rev/f52fdfd12b88
branches:  trunk
changeset: 372755:f52fdfd12b88
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Dec 23 19:37:06 2022 +0000

description:
use malloc instead of alloca so that SSP works.

diffstat:

 usr.sbin/tprof/tprof_top.c |  10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diffs (45 lines):

diff -r 26d9f936d101 -r f52fdfd12b88 usr.sbin/tprof/tprof_top.c
--- a/usr.sbin/tprof/tprof_top.c        Fri Dec 23 19:00:44 2022 +0000
+++ b/usr.sbin/tprof/tprof_top.c        Fri Dec 23 19:37:06 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof_top.c,v 1.7 2022/12/16 08:02:04 ryo Exp $        */
+/*     $NetBSD: tprof_top.c,v 1.8 2022/12/23 19:37:06 christos Exp $   */
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.7 2022/12/16 08:02:04 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.8 2022/12/23 19:37:06 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -194,7 +194,9 @@
        if (*lim <= 0)
                return 0;
 
-       p = alloca(*lim + 1);
+       p = malloc(*lim + 1);
+       if (p == NULL)
+               return -1;
 
        va_start(ap, fmt);
        vsnprintf(p, *lim + 1, fmt, ap);
@@ -202,6 +204,7 @@
 
        written = strlen(p);
        if (written == 0) {
+               free(p);
                *lim = 0;
                return 0;
        }
@@ -209,6 +212,7 @@
        fwrite(p, written, 1, stdout);
        *lim -= written;
 
+       free(p);
        return written;
 }
 



Home | Main Index | Thread Index | Old Index