From: Dmitry V. Levin Date: Mon, 8 Oct 2007 21:04:41 +0000 (+0000) Subject: 2007-09-25 Dmitry V. Levin X-Git-Tag: v4.5.18~131 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=08b623eb84266d4a2defc619fa78400c4e4f0dc1;p=strace 2007-09-25 Dmitry V. Levin * strace (main): Use calloc for tcbtab allocation. Check calloc return value. Reported by Bai Weidong. --- diff --git a/ChangeLog b/ChangeLog index 83cd896e..9897d4b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-09-25 Dmitry V. Levin + + * strace (main): Use calloc for tcbtab allocation. + Check calloc return value. + Reported by Bai Weidong. + 2007-09-11 Roland McGrath * linux/sparc/syscall.h: Add missing decls. diff --git a/strace.c b/strace.c index e3463105..9d82f586 100644 --- a/strace.c +++ b/strace.c @@ -616,9 +616,7 @@ startup_child (char **argv) } int -main(argc, argv) -int argc; -char *argv[]; +main(int argc, char *argv[]) { extern int optind; extern char *optarg; @@ -628,14 +626,21 @@ char *argv[]; static char buf[BUFSIZ]; + progname = argv[0] ? argv[0] : "strace"; + /* Allocate the initial tcbtab. */ tcbtabsize = argc; /* Surely enough for all -p args. */ - tcbtab = (struct tcb **) malloc (tcbtabsize * sizeof tcbtab[0]); - tcbtab[0] = (struct tcb *) calloc (tcbtabsize, sizeof *tcbtab[0]); + if ((tcbtab = calloc (tcbtabsize, sizeof tcbtab[0])) == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + exit(1); + } + if ((tcbtab[0] = calloc (tcbtabsize, sizeof tcbtab[0][0])) == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + exit(1); + } for (tcp = tcbtab[0]; tcp < &tcbtab[0][tcbtabsize]; ++tcp) tcbtab[tcp - tcbtab[0]] = &tcbtab[0][tcp - tcbtab[0]]; - progname = argv[0]; outf = stderr; interactive = 1; set_sortby(DEFAULT_SORTBY);