diff options
author | Ulrich Drepper <drepper@redhat.com> | 2001-12-06 08:49:08 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2001-12-06 08:49:08 +0000 |
commit | 383bd1c5033b466ffcc1a0be766d8a8b003c73e9 (patch) | |
tree | 06aec2446da55eee38518fb8296728d0910f258d /posix | |
parent | 1e06620a7b9c6c65284c52b4625eabd23b14c77c (diff) | |
download | glibc-383bd1c5033b466ffcc1a0be766d8a8b003c73e9.tar.gz glibc-383bd1c5033b466ffcc1a0be766d8a8b003c73e9.tar.xz glibc-383bd1c5033b466ffcc1a0be766d8a8b003c73e9.zip |
Update.
2001-12-06 Ulrich Drepper <drepper@redhat.com> * libio/vasprintf.c (_IO_vasprintf): Free buffer on failure. * assert/assert.c: Check result of __asprintf call and don't use string if it failed. * assert/assert-perr.c: Likewise. * inet/rcmd.c: Likewise. * locale/programs/localedef.c (main): Check result of construct_output_path and exit if it failed. (construct_output_path): Check result of asprintf and mkdir calls and fail if they failed. * posix/getopt.c: Check result of __asprintf calls and fail if they failed. Patch by Dmitry V. Levin <ldv@alt-linux.org>.
Diffstat (limited to 'posix')
-rw-r--r-- | posix/getopt.c | 195 |
1 files changed, 108 insertions, 87 deletions
diff --git a/posix/getopt.c b/posix/getopt.c index 58ba10431c..2e929b71bf 100644 --- a/posix/getopt.c +++ b/posix/getopt.c @@ -685,15 +685,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) #if defined _LIBC && defined USE_IN_LIBIO char *buf; - __asprintf (&buf, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[optind]); + if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[optind]) >= 0) + { - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #else fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); @@ -721,15 +723,16 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; + int n; #endif if (argv[optind - 1][1] == '-') { /* --option */ #if defined _LIBC && defined USE_IN_LIBIO - __asprintf (&buf, _("\ + n = __asprintf (&buf, _("\ %s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); + argv[0], pfound->name); #else fprintf (stderr, _("\ %s: option `--%s' doesn't allow an argument\n"), @@ -740,10 +743,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { /* +option or -option */ #if defined _LIBC && defined USE_IN_LIBIO - __asprintf (&buf, _("\ + n = __asprintf (&buf, _("\ %s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[optind - 1][0], - pfound->name); + argv[0], argv[optind - 1][0], + pfound->name); #else fprintf (stderr, _("\ %s: option `%c%s' doesn't allow an argument\n"), @@ -752,12 +755,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) } #if defined _LIBC && defined USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (n >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #endif } @@ -778,16 +784,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) #if defined _LIBC && defined USE_IN_LIBIO char *buf; - __asprintf (&buf, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (__asprintf (&buf, _("\ +%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]) >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #else fprintf (stderr, _("%s: option `%s' requires an argument\n"), @@ -821,14 +828,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; + int n; #endif if (argv[optind][1] == '-') { /* --option */ #if defined _LIBC && defined USE_IN_LIBIO - __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); + n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), + argv[0], nextchar); #else fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0], nextchar); @@ -838,8 +846,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { /* +option or -option */ #if defined _LIBC && defined USE_IN_LIBIO - __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[optind][0], nextchar); + n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), + argv[0], argv[optind][0], nextchar); #else fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0], argv[optind][0], nextchar); @@ -847,12 +855,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) } #if defined _LIBC && defined USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (n >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #endif } nextchar = (char *) ""; @@ -878,14 +889,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; + int n; #endif if (posixly_correct) { /* 1003.2 specifies the format of this message. */ #if defined _LIBC && defined USE_IN_LIBIO - __asprintf (&buf, _("%s: illegal option -- %c\n"), - argv[0], c); + n = __asprintf (&buf, _("%s: illegal option -- %c\n"), + argv[0], c); #else fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); #endif @@ -893,20 +905,23 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) else { #if defined _LIBC && defined USE_IN_LIBIO - __asprintf (&buf, _("%s: invalid option -- %c\n"), - argv[0], c); + n = __asprintf (&buf, _("%s: invalid option -- %c\n"), + argv[0], c); #else fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); #endif } #if defined _LIBC && defined USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (n >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #endif } optopt = c; @@ -939,15 +954,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) #if defined _LIBC && defined USE_IN_LIBIO char *buf; - __asprintf (&buf, _("%s: option requires an argument -- %c\n"), - argv[0], c); - - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (__asprintf (&buf, + _("%s: option requires an argument -- %c\n"), + argv[0], c) >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #else fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); @@ -1001,15 +1018,16 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) #if defined _LIBC && defined USE_IN_LIBIO char *buf; - __asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[optind]); - - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[optind]) >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #else fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], argv[optind]); @@ -1035,16 +1053,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) #if defined _LIBC && defined USE_IN_LIBIO char *buf; - __asprintf (&buf, _("\ + if (__asprintf (&buf, _("\ %s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); - - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); - - free (buf); + argv[0], pfound->name) >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); + } #else fprintf (stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), @@ -1067,16 +1086,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) #if defined _LIBC && defined USE_IN_LIBIO char *buf; - __asprintf (&buf, _("\ + if (__asprintf (&buf, _("\ %s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); - - free (buf); + argv[0], argv[optind - 1]) >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); + } #else fprintf (stderr, _("%s: option `%s' requires an argument\n"), @@ -1132,16 +1152,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) #if defined _LIBC && defined USE_IN_LIBIO char *buf; - __asprintf (&buf, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + if (__asprintf (&buf, _("\ +%s: option requires an argument -- %c\n"), + argv[0], c) >= 0) + { + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); - free (buf); + free (buf); + } #else fprintf (stderr, _("%s: option requires an argument -- %c\n"), |