scheme-script does not pass through the command line uninterpreted

Bug #256191 reported by Gwen Weinholt
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
Medium
Abdulaziz Ghuloum

Bug Description

The scheme-script program should probably not interpret the arguments passed to the script it's starting.

$ cat command-line
#!/usr/bin/env scheme-script
(import (rnrs))
(display (command-line))
(newline)
$ ./command-line
("./command-line")
$ ./command-line -x
("./command-line" "-x")
$ ./command-line -b
ikarus error: option -b requires a value, none provided
ikarus -h for more help

Related branches

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Will fix.

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

fixed in 1578.

Changed in ikarus:
status: Confirmed → Fix Committed
Revision history for this message
Derick Eddington (derick-eddington) wrote :

There are still some more related issues:

$ cat command-line
#!/usr/bin/env scheme-script
(import (rnrs))
(write (command-line)) (newline)

Arguments to ikarus get split:

$ ./command-line foo "bar baz"
("./command-line" "foo" "bar baz")
$ ikarus --r6rs-script command-line foo "bar baz"
("command-line" "foo" "bar" "baz")
$ ikarus -- foo "bar baz"
Ikarus Scheme version 0.0.3+ (revision 1579, build 2008-08-09)
Copyright (c) 2006-2008 Abdulaziz Ghuloum

> (command-line)
("*interactive*" "foo" "bar" "baz")
>

ikarus --r6rs-script is not equivalent to scheme-script:

$ ./command-line -b
("./command-line" "-b")
$ ikarus --r6rs-script command-line -b
ikarus error: option -b requires a value, none provided
ikarus -h for more help

I'm glad to investigate how to fix these.

Changed in ikarus:
status: Fix Committed → In Progress
Revision history for this message
Derick Eddington (derick-eddington) wrote : Re: [Bug 256191] Re: scheme-script does not pass through the command line uninterpreted

On Sat, 2008-08-09 at 19:28 +0000, Derick Eddington wrote:
> Arguments to ikarus get split:
>
> $ ./command-line foo "bar baz"
> ("./command-line" "foo" "bar baz")
> $ ikarus --r6rs-script command-line foo "bar baz"
> ("command-line" "foo" "bar" "baz")
> $ ikarus -- foo "bar baz"
> Ikarus Scheme version 0.0.3+ (revision 1579, build 2008-08-09)
> Copyright (c) 2006-2008 Abdulaziz Ghuloum
>
> > (command-line)
> ("*interactive*" "foo" "bar" "baz")
> >

That splitting of the arguments is because of my custom ikarus-mine.sh
wrapper aliased to ikarus. It's not an issue with Ikarus. Sorry.

Revision history for this message
Derick Eddington (derick-eddington) wrote :
Download full text (3.2 KiB)

On Sat, 2008-08-09 at 19:28 +0000, Derick Eddington wrote:
> ikarus --r6rs-script is not equivalent to scheme-script:
>
> $ ./command-line -b
> ("./command-line" "-b")
> $ ikarus --r6rs-script command-line -b
> ikarus error: option -b requires a value, none provided
> ikarus -h for more help
>
>
> I'm glad to investigate how to fix these.

Here's what I've done to fix --r6rs-script and --script :

=== modified file 'src/ikarus.c'
--- src/ikarus.c 2008-08-09 12:47:44 +0000
+++ src/ikarus.c 2008-08-09 22:06:48 +0000
@@ -82,7 +82,9 @@
         exit(-1);
       }
     }
- else if(strcmp("--", argv[i]) == 0){
+ else if(strcmp("--", argv[i]) == 0
+ || strcmp("--r6rs-script", argv[i]) == 0
+ || strcmp("--script", argv[i]) == 0){
       return 0;
     }
   }
@@ -100,7 +102,9 @@
         }
       return 1;
     }
- else if(strcmp("--", argv[i]) == 0){
+ else if(strcmp("--", argv[i]) == 0
+ || strcmp("--r6rs-script", argv[i]) == 0
+ || strcmp("--script", argv[i]) == 0){
       return 0;
     }
   }

And now scheme-script can go back to just exec'ing ikarus:
[You'll still need to do automake.]

=== modified file 'src/Makefile.am'
--- src/Makefile.am 2008-08-09 12:47:44 +0000
+++ src/Makefile.am 2008-08-09 23:19:23 +0000
@@ -10,7 +10,7 @@
   ikarus-errno.c ikarus-main.h

 ikarus_SOURCES = $(SRCS) ikarus.c
-scheme_script_SOURCES = $(SRCS) scheme-script.c
+scheme_script_SOURCES = scheme-script.c

 nodist_ikarus_SOURCES = bootfileloc.h
 BUILT_SOURCES = bootfileloc.h

=== modified file 'src/scheme-script.c'
--- src/scheme-script.c 2008-08-09 12:47:44 +0000
+++ src/scheme-script.c 2008-08-09 23:27:18 +0000
@@ -15,20 +15,14 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */

-
-
-#include "ikarus-main.h"
 #include "bootfileloc.h"
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-void ikarus_usage_short(){
- fprintf(stderr, "scheme-script <script-name> arguments ...\n");
-}
-
-void ikarus_usage(){
+#include <unistd.h>
+#include <errno.h>
+
+static void usage(){
   static char* helpstring =
   "Usage: \n\
   scheme-script <script-name> arguments ...\n\
@@ -42,19 +36,25 @@

 int main(int argc, char** argv){
   if(argc < 2) {
- ikarus_usage();
- exit(-1);
- }
- char* boot_file = BOOTFILE;
- char** args = calloc(sizeof(char*), argc+1);
- args[0] = argv[0];
+ usage();
+ exit(-1);
+ }
+ char** args = calloc(argc+2, sizeof(char*));
+ if(! args) {
+ fprintf(stderr, "Error in scheme-script: cannot calloc\n");
+ exit(-1);
+ }
+ args[0] = EXEFILE;
   args[1] = "--r6rs-script";
- args[2] = argv[1];
   int i;
   for(i=1; i<argc; i++){
     args[i+1] = argv[i];
   }
- return ikarus_main(argc+1, args, boot_file);
+ args[argc+1] = 0;
+ execv(EXEFILE, args);
+ fprintf(stderr, "Error executing ikarus from scheme-script: %s\n",
+ strerror(errno));
+ exit(-1);
 }

Also, a minor something I just noticed about when scheme-script is made
to just exec ikarus (including prior to revision 1578): the autoconf
configuration is linking scheme-script with libgmp, libm, and libdl but
it doesn't nee...

Read more...

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 256191] Re: scheme-script does not pass through the command line uninterpreted

On Aug 9, 2008, at 12:28 PM, Derick Eddington wrote:

> $ cat command-line
> #!/usr/bin/env scheme-script
> (import (rnrs))
> (write (command-line)) (newline)
>
>
> Arguments to ikarus get split:
>
> $ ./command-line foo "bar baz"
> ("./command-line" "foo" "bar baz")
> $ ikarus --r6rs-script command-line foo "bar baz"
> ("command-line" "foo" "bar" "baz")

Not under darwin:

$ ./command-line foo "bar baz"
("./command-line" "foo" "bar baz")

$ ikarus --r6rs-script ./command-line foo "bar baz"
("./command-line" "foo" "bar baz")

Go figure now who's splitting those (not me) and why.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 256191] Re: scheme-script does not pass through the command line uninterpreted

On Aug 9, 2008, at 5:23 PM, Derick Eddington wrote:

> - else if(strcmp("--", argv[i]) == 0){
> + else if(strcmp("--", argv[i]) == 0
> + || strcmp("--r6rs-script", argv[i]) == 0
> + || strcmp("--script", argv[i]) == 0){
> return 0;

I don't like this since it requires changing the C command line
parser every time I change ikarus's arguments (e.g., you already
forgot -O0, -O1, -O2).

I think the better option is to have all C arguments (which are
only "-b bootfile" now) to come before the Scheme arguments (e.g.,
--r6rs-script, --script, etc.,) and all Scheme arguments to come
before the user's program arguments.

I haven't given much thought to these arguments up to this point.
It might need a little more thought.

Revision history for this message
Derick Eddington (derick-eddington) wrote : Re: [Bug 256191] Re: scheme-script does not pass through the command line uninterpreted

On Sun, 2008-08-10 at 10:27 -0700, Abdulaziz Ghuloum wrote:
> On Aug 9, 2008, at 5:23 PM, Derick Eddington wrote:
>
> > - else if(strcmp("--", argv[i]) == 0){
> > + else if(strcmp("--", argv[i]) == 0
> > + || strcmp("--r6rs-script", argv[i]) == 0
> > + || strcmp("--script", argv[i]) == 0){
> > return 0;
>
> I don't like this since it requires changing the C command line
> parser every time I change ikarus's arguments (e.g., you already
> forgot -O0, -O1, -O2).

I was only attempting to protect the user program's arguments and for
that the -ON currently don't matter, but I understand what you mean
about design-for-the-future and maintenance.

I did forget --compile-dependencies, which in ikarus.main.ss uses the
arguments after its script name.

> I think the better option is to have all C arguments (which are
> only "-b bootfile" now)

and -h

> and all Scheme arguments to come
> before the user's program arguments.

ikarus.main.ss already does that.

I agree a less-maintenance-required solution would be nicer, but how
could it be done?

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 256191] Re: scheme-script does not pass through the command line uninterpreted

On Aug 9, 2008, at 5:23 PM, Derick Eddington wrote:

> Also, a minor something I just noticed about when scheme-script is
> made
> to just exec ikarus (including prior to revision 1578): the autoconf
> configuration is linking scheme-script with libgmp, libm, and libdl
> but
> it doesn't need to be linked with those.

I didn't think execing ikarus is a good idea and that's why I changed
it.
Reasons for the change: 1. don't think about what happens if ikarus is
deleted, 2. what if exec is unreliable (can't trust cygwin really),
3. the
executable size is less than 100K in my system and is unlikely to
grow by
much, so, I can't care about saving disk space.

Revision history for this message
Derick Eddington (derick-eddington) wrote : Re: [Bug 256191] Re: scheme-script does not pass through the command line uninterpreted

On Sun, 2008-08-10 at 13:47 -0700, Abdulaziz Ghuloum wrote:
> I didn't think execing ikarus is a good idea and that's why I changed
> it.
> Reasons for the change: 1. don't think about what happens if ikarus is
> deleted, 2. what if exec is unreliable (can't trust cygwin really),

Ah, good reasons.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Last I checked on this bug, you said:
  I agree a less-maintenance-required solution would be nicer, but how could it be done?

(and I was lost because the log of this bug report is all scrambled)

What's the status here? Are there any issues pending?

Revision history for this message
Derick Eddington (derick-eddington) wrote :

There's still the issue that ikarus is eating user program's arguments:

[d@eep:~/t9]-> cat command-line.sps
(import (rnrs))
(write (command-line)) (newline)
[d@eep:~/t9]-> ikarus --r6rs-script command-line.sps foo bar -b
ikarus error: option -b requires a value, none provided
ikarus -h for more help
[d@eep:~/t9]-> scheme-script command-line.sps foo bar -b
("command-line.sps" "foo" "bar" "-b")
[d@eep:~/t9]->

Also, "ikarus --r6rs-script" is allowing load files to precede "--r6rs-script" but they are ignored (same for "--compile-dependencies"). I suggest an error happen if there are load files in this case.

[d@eep:~/t9]-> ikarus oops0 oops1 --r6rs-script command-line.sps foo bar
("command-line.sps" "foo" "bar")
[d@eep:~/t9]->

Attached is a patch to fix both these things. With it:

[d@eep:~/t9]-> ikarus --r6rs-script command-line.sps foo bar -b
("command-line.sps" "foo" "bar" "-b")
[d@eep:~/t9]-> ikarus oops0 oops1 --r6rs-script command-line.sps foo bar
Unhandled exception:
 Condition components:
   1. &assertion
   2. &who: ikarus
   3. &message: "load files not allowed for --r6rs-script"
   4. &irritants: ("oops0" "oops1")
[d@eep:~/t9]->

Unlike my previous patch, this one is less-maintenance-required for the protected "stop processing at" arguments, handles "--compile-dependencies", and errors if there are inappropriate load files.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed in 1637 with a few changes, mainly, that ikarus.c now does not scan past the first argument to find -h and -b options.

Changed in ikarus:
status: In Progress → Fix Committed
Changed in ikarus:
milestone: none → 0.0.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.