2007-09-25 Dmitry V. Levin <ldv@altlinux.org>

* strace (main): Use calloc for tcbtab allocation.
	Check calloc return value.
	Reported by Bai Weidong.
This commit is contained in:
Дмитрий Левин 2007-10-08 21:04:41 +00:00
parent 4df814ff8f
commit 08b623eb84
2 changed files with 17 additions and 6 deletions

View File

@ -1,3 +1,9 @@
2007-09-25 Dmitry V. Levin <ldv@altlinux.org>
* strace (main): Use calloc for tcbtab allocation.
Check calloc return value.
Reported by Bai Weidong.
2007-09-11 Roland McGrath <roland@redhat.com>
* linux/sparc/syscall.h: Add missing decls.

View File

@ -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);