[tz] [PROPOSED] Don’t assume nonempty argv

enh enh at google.com
Sat Oct 29 14:49:01 UTC 2022


On Fri, Oct 28, 2022 at 11:56 PM Paul Eggert via tz <tz at iana.org> wrote:

> Don’t dump core if argv[0] is NULL, which is allowed on
> GNU/Linux if the invoker is sufficiently perverse.
>

note that linux fixed this earlier this year:
https://github.com/torvalds/linux/commit/dcd46d897adb70d63e025f175a00a89797d31a43


> * zdump.c (progname): Now char const *, so that it can be given
> the address of a string constant.
> (tzalloc): Use optarg, not progname, since progname’s type is no
> longer correct.
> * zdump.c, zic.c (main): Initialize progname to non-null.
> ---
>  zdump.c | 6 +++---
>  zic.c   | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/zdump.c b/zdump.c
> index 512ba8cc..f0461ade 100644
> --- a/zdump.c
> +++ b/zdump.c
> @@ -84,7 +84,7 @@ static time_t const absolute_max_time =
>     ? (((time_t) 1 << atime_shift) - 1 + ((time_t) 1 << atime_shift))
>     : -1);
>  static int     longest;
> -static char *  progname;
> +static char const *progname;
>  static bool    warned;
>  static bool    errout;
>
> @@ -234,7 +234,7 @@ tzalloc(char const *val)
>      exit(EXIT_FAILURE);
>    }
>    tzset();
> -  return &progname;  /* Any valid non-null char ** will do.  */
> +  return &optarg;  /* Any valid non-null char ** will do.  */
>  # else
>    enum { TZeqlen = 3 };
>    static char const TZeq[TZeqlen] = "TZ=";
> @@ -463,7 +463,7 @@ main(int argc, char *argv[])
>  # endif /* defined TEXTDOMAINDIR */
>         textdomain(TZ_DOMAIN);
>  #endif /* HAVE_GETTEXT */
> -       progname = argv[0];
> +       progname = argv[0] ? argv[0] : "zdump";
>         for (i = 1; i < argc; ++i)
>                 if (strcmp(argv[i], "--version") == 0) {
>                         printf("zdump %s%s\n", PKGVERSION, TZVERSION);
> diff --git a/zic.c b/zic.c
> index 501718f4..f3b32ecc 100644
> --- a/zic.c
> +++ b/zic.c
> @@ -943,7 +943,7 @@ main(int argc, char **argv)
>         textdomain(TZ_DOMAIN);
>  #endif /* HAVE_GETTEXT */
>         main_argv = argv;
> -       progname = argv[0];
> +       progname = argv[0] ? argv[0] : "zic";
>         if (TYPE_BIT(zic_t) < 64) {
>                 fprintf(stderr, "%s: %s\n", progname,
>                         _("wild compilation-time specification of zic_t"));
> --
> 2.37.2
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mm.icann.org/pipermail/tz/attachments/20221029/a618486e/attachment.htm>


More information about the tz mailing list