unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#26013: (srfi srfi-37) chokes on empty string parameter
@ 2017-03-07 15:34 Thomas Danckaert
  2017-04-19 15:13 ` Andy Wingo
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Danckaert @ 2017-03-07 15:34 UTC (permalink / raw)
  To: 26013

Hello Guilers,

It looks like Guile's srfi-37 implementation doesn't process empty 
string arguments correctly.  For example, here's a stacktrace I get 
when executing guix system list-generations "":

$ guix system list-generations ""
Backtrace:
In ice-9/boot-9.scm:
  160: 15 [catch #t #<catch-closure 188c1c0> ...]
In unknown file:
    ?: 14 [apply-smob/1 #<catch-closure 188c1c0>]
In ice-9/boot-9.scm:
   66: 13 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
  432: 12 [eval # #]
In ice-9/boot-9.scm:
2404: 11 [save-module-excursion #<procedure 18af900 at 
ice-9/boot-9.scm:4051:3 ()>]
4056: 10 [#<procedure 18af900 at ice-9/boot-9.scm:4051:3 ()>]
1727: 9 [%start-stack load-stack ...]
1732: 8 [#<procedure 18c3b70 ()>]
In unknown file:
    ?: 7 [primitive-load 
"/gnu/store/hnbqdmfh1bwma8nmpai6ci76h5j6bl7j-guix-0.12.0-4.d9da/bin/.guix-real"]
In guix/ui.scm:
1228: 6 [run-guix-command system "list-generations" ""]
In ice-9/boot-9.scm:
  160: 5 [catch srfi-34 #<procedure 47e1580 at guix/ui.scm:432:2 ()> 
...]
  160: 4 [catch system-error ...]
In guix/scripts/system.scm:
  947: 3 [#<procedure 47e2b10 at guix/scripts/system.scm:946:2 ()>]
In ice-9/boot-9.scm:
  160: 2 [catch misc-error #<procedure 47e4c00 at 
guix/scripts.scm:48:4 ()> ...]
In srfi/srfi-37.scm:
  220: 1 [next-arg]
In unknown file:
    ?: 0 [string-ref "" 0]

ERROR: In procedure string-ref:
ERROR: Value out of range: 0

cheers,

Thomas





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#26013: (srfi srfi-37) chokes on empty string parameter
  2017-03-07 15:34 bug#26013: (srfi srfi-37) chokes on empty string parameter Thomas Danckaert
@ 2017-04-19 15:13 ` Andy Wingo
  2017-04-19 16:32   ` Thomas Danckaert
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2017-04-19 15:13 UTC (permalink / raw)
  To: Thomas Danckaert; +Cc: ludo, 26013

On Tue 07 Mar 2017 16:34, Thomas Danckaert <post@thomasdanckaert.be> writes:

> It looks like Guile's srfi-37 implementation doesn't process empty
> string arguments correctly.  For example, here's a stacktrace I get when
> executing guix system list-generations "":
>
> $ guix system list-generations ""
> Backtrace:
> In ice-9/boot-9.scm:
>  160: 15 [catch #t #<catch-closure 188c1c0> ...]
> In unknown file:
>    ?: 14 [apply-smob/1 #<catch-closure 188c1c0>]
> In ice-9/boot-9.scm:
>   66: 13 [call-with-prompt prompt0 ...]
> In ice-9/eval.scm:
>  432: 12 [eval # #]
> In ice-9/boot-9.scm:
> 2404: 11 [save-module-excursion #<procedure 18af900 at
> ice-9/boot-9.scm:4051:3 ()>]
> 4056: 10 [#<procedure 18af900 at ice-9/boot-9.scm:4051:3 ()>]
> 1727: 9 [%start-stack load-stack ...]
> 1732: 8 [#<procedure 18c3b70 ()>]
> In unknown file:
>    ?: 7 [primitive-load
> "/gnu/store/hnbqdmfh1bwma8nmpai6ci76h5j6bl7j-guix-0.12.0-4.d9da/bin/.guix-real"]
> In guix/ui.scm:
> 1228: 6 [run-guix-command system "list-generations" ""]
> In ice-9/boot-9.scm:
>  160: 5 [catch srfi-34 #<procedure 47e1580 at guix/ui.scm:432:2 ()> ...]
>  160: 4 [catch system-error ...]
> In guix/scripts/system.scm:
>  947: 3 [#<procedure 47e2b10 at guix/scripts/system.scm:946:2 ()>]
> In ice-9/boot-9.scm:
>  160: 2 [catch misc-error #<procedure 47e4c00 at guix/scripts.scm:48:4
> ()> ...]
> In srfi/srfi-37.scm:
>  220: 1 [next-arg]
> In unknown file:
>    ?: 0 [string-ref "" 0]
>
> ERROR: In procedure string-ref:
> ERROR: Value out of range: 0

Sounds like the right diagnosis to me.  Want to submit a patch? :)

Andy





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#26013: (srfi srfi-37) chokes on empty string parameter
  2017-04-19 15:13 ` Andy Wingo
@ 2017-04-19 16:32   ` Thomas Danckaert
  2017-04-20  8:59     ` Andy Wingo
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Danckaert @ 2017-04-19 16:32 UTC (permalink / raw)
  To: wingo; +Cc: ludo, 26013

[-- Attachment #1: Type: Text/Plain, Size: 919 bytes --]

From: Andy Wingo <wingo@igalia.com>
Subject: Re: bug#26013: (srfi srfi-37) chokes on empty string 
parameter
Date: Wed, 19 Apr 2017 17:13:25 +0200

> On Tue 07 Mar 2017 16:34, Thomas Danckaert 
> <post@thomasdanckaert.be> writes:
>
>> It looks like Guile's srfi-37 implementation doesn't process empty
>> string arguments correctly.
>> [...]
>> In srfi/srfi-37.scm:
>>  220: 1 [next-arg]
>> In unknown file:
>>    ?: 0 [string-ref "" 0]
>>
>> ERROR: In procedure string-ref:
>> ERROR: Value out of range: 0
>
> Sounds like the right diagnosis to me.  Want to submit a patch? :)

Well, let me try :)

I don't fully understand the code in srfi-37.scm, but I think the fix 
can be as simple as the attached patch (i.e. first check if the 
argument is empty, otherwise check if it starts with \#-).

I have tried to follow the existing indentation convention, as far as 
I understand it (a mix of tabs and spaces).

Thomas

[-- Attachment #2: 0001-SRFI-37-Account-for-zero-length-arguments.patch --]
[-- Type: Text/X-Patch, Size: 1018 bytes --]

From bd0bd95e3786211effe728bae61ef5b02f6cc5f6 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <thomas.danckaert@gmail.com>
Date: Wed, 19 Apr 2017 18:14:38 +0200
Subject: [PATCH] SRFI-37: Account for zero-length arguments.

* module/srfi/srfi-37.scm (args-fold): When checking if an argument is
an option (starts with #\-), first check if the length is non-zero.
---
 module/srfi/srfi-37.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/module/srfi/srfi-37.scm b/module/srfi/srfi-37.scm
index 3f654af2c..c34b0d083 100644
--- a/module/srfi/srfi-37.scm
+++ b/module/srfi/srfi-37.scm
@@ -217,7 +217,8 @@ program-arguments in ARGS, as decided by the OPTIONS'
       (if (null? args)
 	  (apply values seeds)
 	  (let ((arg (car args)))
-	    (cond ((or (not (char=? #\- (string-ref arg 0)))
+	    (cond ((or (string-null? arg)
+		       (not (char=? #\- (string-ref arg 0)))
 		       (= 1 (string-length arg))) ;"-"
 		   (mutate-seeds! operand-proc arg)
 		   (set! args (cdr args)))
-- 
2.12.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#26013: (srfi srfi-37) chokes on empty string parameter
  2017-04-19 16:32   ` Thomas Danckaert
@ 2017-04-20  8:59     ` Andy Wingo
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2017-04-20  8:59 UTC (permalink / raw)
  To: Thomas Danckaert; +Cc: 26013-done, ludo

On Wed 19 Apr 2017 18:32, Thomas Danckaert <post@thomasdanckaert.be> writes:

>> On Tue 07 Mar 2017 16:34, Thomas Danckaert <post@thomasdanckaert.be>
>> writes:
>>
>>> It looks like Guile's srfi-37 implementation doesn't process empty
>>> string arguments correctly.
> I don't fully understand the code in srfi-37.scm, but I think the fix
> can be as simple as the attached patch (i.e. first check if the argument
> is empty, otherwise check if it starts with \#-).

Applied, thanks :)

Andy





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-20  8:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-07 15:34 bug#26013: (srfi srfi-37) chokes on empty string parameter Thomas Danckaert
2017-04-19 15:13 ` Andy Wingo
2017-04-19 16:32   ` Thomas Danckaert
2017-04-20  8:59     ` Andy Wingo

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).