diff --git a/src/ChangeLog b/src/ChangeLog index 9364d54d..13ab1ae7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2012-02-23 Giuseppe Scrivano + * main.c (main): Fail gracefully if `malloc' fails. + * gnutls.c (wgnutls_read): Remove unused variables `timer' and `flags'. 2012-02-17 Steven Schubiger diff --git a/src/main.c b/src/main.c index 5aa528de..9eefc98f 100644 --- a/src/main.c +++ b/src/main.c @@ -988,15 +988,20 @@ main (int argc, char **argv) for (i = 1; i < argc; i++) argstring_length += strlen (argv[i]) + 2 + 1; char *p = program_argstring = malloc (argstring_length * sizeof (char)); + if (p == NULL) + { + fprintf (stderr, _("Memory allocation problem\n")); + exit (2); + } for (i = 1; i < argc; i++) - { - *p++ = '"'; - int arglen = strlen (argv[i]); - memcpy (p, argv[i], arglen); - p += arglen; - *p++ = '"'; - *p++ = ' '; - } + { + *p++ = '"'; + int arglen = strlen (argv[i]); + memcpy (p, argv[i], arglen); + p += arglen; + *p++ = '"'; + *p++ = ' '; + } *p = '\0'; /* Load the hard-coded defaults. */ @@ -1355,6 +1360,11 @@ for details.\n\n")); /* Fill in the arguments. */ url = alloca_array (char *, nurl + 1); + if (url == NULL) + { + fprintf (stderr, _("Memory allocation problem\n")); + exit (2); + } for (i = 0; i < nurl; i++, optind++) { char *rewritten = rewrite_shorthand_url (argv[optind]);