From: Bai W. <ba...@cn...> - 2007-09-25 01:15:11
|
hello: I am afraid that strace may need minor changes on strace allocating memory failed. Could you please review patch? Thank you very much. Signed-off-by: "Bai Weidong" <ba...@cn...> Best Regards --- strace-4.5.15/straceold.c 2007-09-24 11:05:43.000000000 +0800 +++ strace-4.5.15/strace.c 2007-09-24 17:18:18.000000000 +0800 @@ -335,7 +335,17 @@ char *argv[]; /* Allocate the initial tcbtab. */ tcbtabsize = argc; /* Surely enough for all -p args. */ tcbtab = (struct tcb **) malloc (tcbtabsize * sizeof tcbtab[0]); + if (tcbtab == NULL) { + fprintf(stderr, "%s: out of memory\n", + progname); + exit(1); + } tcbtab[0] = (struct tcb *) calloc (tcbtabsize, sizeof *tcbtab[0]); + if (tcbtab[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]]; |
From: Dmitry V. L. <ld...@al...> - 2007-10-08 21:08:30
|
OK, commited as obvious. On Wed, Sep 26, 2007 at 08:32:04AM +0800, Bai Weidong wrote: > On Tue, Sep 25, 2007 at 05:26:13PM +0400, Dmitry V. Levin wrote: > > On Tue, Sep 25, 2007 at 09:13:09AM +0800, Bai Weidong wrote: > > hello: > > I am afraid that strace may need minor changes on strace=20 > > allocating memory failed. >=20 > >Here is a test case for linux/i686: > >$ ulimit -v 6144 && strace `perl -e "print \"'' \" x 32700"` > >Segmentation fault >=20 > >I propose a bit different patch to fix this. > . > Thank you for your reviewing very much. Your patch is right. >=20 > >--- a/strace/strace.c > >+++ b/strace/strace.c > >@@ -345,9 +345,7 @@ newoutf(struct tcb *tcp) > > } > =20 > > int > >-main(argc, argv) > >-int argc; > >-char *argv[]; > >+main(int argc, char *argv[]) > > { > > extern int optind; > > extern char *optarg; > >@@ -357,14 +355,21 @@ char *argv[]; > >=20 > > static char buf[BUFSIZ]; > > > >+ progname =3D argv[0] ? argv[0] : "strace"; > >+ > > /* Allocate the initial tcbtab. */ > > tcbtabsize =3D argc; /* Surely enough for all -p args. */ > >- tcbtab =3D (struct tcb **) malloc (tcbtabsize * sizeof tcbtab[0]); > >- tcbtab[0] =3D (struct tcb *) calloc (tcbtabsize, sizeof *tcbtab[0]); > >+ if ((tcbtab =3D calloc (tcbtabsize, sizeof tcbtab[0])) =3D=3D NULL) { > >+ fprintf(stderr, "%s: out of memory\n", progname); > >+ exit(1); > >+ } > >+ if ((tcbtab[0] =3D calloc (tcbtabsize, sizeof tcbtab[0][0])) =3D=3D NU= LL) { > >+ fprintf(stderr, "%s: out of memory\n", progname); > >+ exit(1); > >+ } > > for (tcp =3D tcbtab[0]; tcp < &tcbtab[0][tcbtabsize]; ++tcp) > > tcbtab[tcp - tcbtab[0]] =3D &tcbtab[0][tcp - tcbtab[0]]; > >=20 > >- progname =3D argv[0]; > > outf =3D stderr; > > interactive =3D 1; > > set_sortby(DEFAULT_SORTBY); --=20 ldv |