[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] progname: don't segfault when argv is NULL
From: |
Eric Blake |
Subject: |
Re: [PATCH] progname: don't segfault when argv is NULL |
Date: |
Sat, 05 Dec 2009 15:04:04 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Bruno Haible on 12/5/2009 6:08 AM:
> Ad 2):
> This is indeed a kernel problem: OpenBSD 4.0 returns with error code
> EFAULT if you pass NULL to execve or execv or execvp. Linux 2.6.25.20
> does not. Here's the draft for a report to a linux-kernel mailing list.
> Can someone please complete it for me? I am not used any more to rebuild
> and install modified Linux kernels.
I haven't built a modified Linux kernel, either, but your proposed report
looks decent from a first reading.
>
> Ad 3):
> If you really want to do something that eases finding of such a bug in the
> parent process, then - rather than sweeping the bug under the carpet - provide
> an error message, like this.
>
> *** lib/progname.c.orig 2009-12-05 14:07:04.000000000 +0100
> --- lib/progname.c 2009-12-05 13:55:35.000000000 +0100
> ***************
> *** 23,28 ****
> --- 23,30 ----
> #include "progname.h"
>
> #include <errno.h> /* get program_invocation_name declaration */
> + #include <stdio.h>
> + #include <stdlib.h>
> #include <string.h>
>
>
> ***************
> *** 44,49 ****
> --- 46,60 ----
> const char *slash;
> const char *base;
>
> + /* Sanity check. POSIX requires the invoking process to pass a non-NULL
> + argv[0]. */
> + if (argv0 == NULL)
> + {
> + fputs ("A NULL argv[0] was passed through the exec system call.\n",
> + stderr);
> + abort ();
> + }
This seems like a reasonable compromise to me, but I'll let Jim chime in.
It avoids the segfault, while being verbose enough to let the user know
where the real problem lies rather than papering over the problem by
letting the program proceed. However, is the string worth marking as
translatable? Or should it try error() rather than fputs()? (Although
that gets a bit problematic, since error() relies on program_name, which
we have just determined can't be set because argv[0] is NULL.)
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAksa2NQACgkQ84KuGfSFAYCSUwCgrk4iW36Cf5PuaLmK4DwL3hYD
2eUAn3/XUwabRx4Hgf/LRnYpdLmt5LxF
=pwbT
-----END PGP SIGNATURE-----
- [PATCH] progname: don't segfault when argv is NULL, Jim Meyering, 2009/12/04
- Re: [PATCH] progname: don't segfault when argv is NULL, Bruno Haible, 2009/12/04
- Re: [PATCH] progname: don't segfault when argv is NULL, Pádraig Brady, 2009/12/04
- Re: [PATCH] progname: don't segfault when argv is NULL, Eric Blake, 2009/12/04
- Re: [PATCH] progname: don't segfault when argv is NULL, Jim Meyering, 2009/12/05
- Re: [PATCH] progname: don't segfault when argv is NULL, Jim Meyering, 2009/12/06
- __nonnull__ declarations, Bruno Haible, 2009/12/06
- Re: __nonnull__ declarations, Jim Meyering, 2009/12/07
- Re: __nonnull__ declarations, Bruno Haible, 2009/12/10
- Re: [PATCH] progname: don't segfault when argv is NULL, Bruno Haible, 2009/12/06
- Re: [PATCH] progname: don't segfault when argv is NULL, Jim Meyering, 2009/12/09
- Re: [PATCH] progname: don't segfault when argv is NULL, Bruno Haible, 2009/12/09
- Re: [PATCH] progname: don't segfault when argv is NULL, Bruno Haible, 2009/12/09
- Re: [PATCH] progname: don't segfault when argv is NULL, Jim Meyering, 2009/12/09