diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | internal.h | 8 | ||||
-rw-r--r-- | process.c | 8 |
3 files changed, 17 insertions, 7 deletions
@@ -1,3 +1,11 @@ +Mon Jun 4 19:36:25 2012 Tanaka Akira <akr@fsij.org> + + * process.c (rb_exec_fillarg): allocate one more element before + beginning in argv_str for try_with_sh. + + * internal.h (ARGVSTR2ARGC): adjust for the above change. + (ARGVSTR2ARGV): ditto. + Mon Jun 4 19:17:06 2012 Tanaka Akira <akr@fsij.org> * internal.h (ARGVSTR2ARGC): defined. diff --git a/internal.h b/internal.h index 37541cc145..48a3a763d5 100644 --- a/internal.h +++ b/internal.h @@ -159,10 +159,12 @@ st_index_t rb_hash_proc(st_index_t hash, VALUE proc); /* process.c */ -/* argv_str contains an extra element for terminating NULL used by execve.. +/* argv_str contains extra two elements. + * The beginning one is for /bin/sh used by exec_with_sh. + * The last one for terminating NULL used by execve. * See rb_exec_fillarg() in process.c. */ -#define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 1) -#define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str)) +#define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 2) +#define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str) + 1) /* rational.c */ VALUE rb_lcm(VALUE x, VALUE y); @@ -1843,17 +1843,17 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, str } if (e->argv_buf) { - char *p, *ep; + char *p, *ep, *null=NULL; VALUE argv_str; - argv_str = hide_obj(rb_str_buf_new(sizeof(char*) * (argc + 1))); + argv_str = hide_obj(rb_str_buf_new(sizeof(char*) * (argc + 2))); + rb_str_buf_cat(argv_str, (char *)&null, sizeof(null)); /* place holder for /bin/sh of try_with_sh. */ p = RSTRING_PTR(e->argv_buf); ep = p + RSTRING_LEN(e->argv_buf); while (p < ep) { rb_str_buf_cat(argv_str, (char *)&p, sizeof(p)); p += strlen(p) + 1; } - p = NULL; - rb_str_buf_cat(argv_str, (char *)&p, sizeof(p)); + rb_str_buf_cat(argv_str, (char *)&null, sizeof(null)); /* terminator for execve. */ e->argv_str = argv_str; } } |