* bug#18680: [PATCH] Check if argv[0] is NULL in scm_boot_guile to avoid segfault
@ 2014-10-10 16:15 Nala Ginrut
2014-10-11 17:05 ` Mark H Weaver
0 siblings, 1 reply; 2+ messages in thread
From: Nala Ginrut @ 2014-10-10 16:15 UTC (permalink / raw)
To: guile-devel, eliz, wingo, 18680, mhw
[-- Attachment #1: Type: text/plain, Size: 666 bytes --]
This patch is for master branch, but the bug also appears in the
current stable-2.0 I think.
With the recent patch from Eli Zaretskii, there'd be one more step for argv[0]:
scm_i_mirror_backslashes (argv[0]);
But this cause my program segfault, since I have such line:
scm_boot_guile(0, {NULL}, &guilemain, NULL);
According to C11, it's allowed[1].
argv[argc] should be NULL.
If the value of argc is greater than zero, the string pointed to by argv[0]
represents the program name. But if argc is zero, argv[0] will be NULL, so
we have to check it first to avoid segfault.
Attached patch fixed this.
[1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
[-- Attachment #2: 0001-Check-argv-0-if-it-s-NULL-in-scm_boot_guile.patch --]
[-- Type: text/x-patch, Size: 1357 bytes --]
From b6938156fe1ca2ba8a7db167604618eea31282f1 Mon Sep 17 00:00:00 2001
From: Nala Ginrut <nalaginrut@gmail.com>
Date: Fri, 10 Oct 2014 23:54:24 +0800
Subject: [PATCH] Check argv[0] if it's NULL in scm_boot_guile
According to C11, argv[argc] should be NULL.
If the value of argc is greater than zero, the string pointed to by argv[0]
represents the program name. But if argc is zero, argv[0] will be NULL, so
we have to check it first to avoid segfault.
* libguile/init.c
---
libguile/init.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/libguile/init.c b/libguile/init.c
index d2928bd..e11115c 100644
--- a/libguile/init.c
+++ b/libguile/init.c
@@ -311,8 +311,14 @@ scm_boot_guile (int argc, char ** argv, void (*main_func) (), void *closure)
struct main_func_closure c;
/* On Windows, convert backslashes in argv[0] to forward
- slashes. */
- scm_i_mirror_backslashes (argv[0]);
+ slashes.
+ According to C11, argv[argc] should be NULL.
+ If the value of argc is greater than zero, the string pointed to by argv[0]
+ represents the program name. But if argc is zero, argv[0] will be NULL, so
+ we have to check it first to avoid segfault.
+ */
+ if (argc)
+ scm_i_mirror_backslashes (argv[0]);
c.main_func = main_func;
c.closure = closure;
c.argc = argc;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Check if argv[0] is NULL in scm_boot_guile to avoid segfault
2014-10-10 16:15 bug#18680: [PATCH] Check if argv[0] is NULL in scm_boot_guile to avoid segfault Nala Ginrut
@ 2014-10-11 17:05 ` Mark H Weaver
0 siblings, 0 replies; 2+ messages in thread
From: Mark H Weaver @ 2014-10-11 17:05 UTC (permalink / raw)
To: Nala Ginrut; +Cc: 18680-done, Andy Wingo, guile-devel
Nala Ginrut <nalaginrut@gmail.com> writes:
> This patch is for master branch, but the bug also appears in the
> current stable-2.0 I think.
>
> With the recent patch from Eli Zaretskii, there'd be one more step for argv[0]:
> scm_i_mirror_backslashes (argv[0]);
>
> But this cause my program segfault, since I have such line:
> scm_boot_guile(0, {NULL}, &guilemain, NULL);
>
> According to C11, it's allowed[1].
> argv[argc] should be NULL.
> If the value of argc is greater than zero, the string pointed to by argv[0]
> represents the program name. But if argc is zero, argv[0] will be NULL, so
> we have to check it first to avoid segfault.
Fixed in b9ace68613395fda26f3f3d7dc2ac9bc52cd7f2a on the stable-2.0
branch. It'll go into master on the next merge.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-11 17:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-10 16:15 bug#18680: [PATCH] Check if argv[0] is NULL in scm_boot_guile to avoid segfault Nala Ginrut
2014-10-11 17:05 ` Mark H Weaver
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).