Project

General

Profile

Actions

Bug #10535

closed

Potential uninitialized reference pipe_open() in io.c

Bug #10535: Potential uninitialized reference pipe_open() in io.c

Added by asm (Andy Maloney) almost 11 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-11-22 trunk 48537) [x86_64-darwin12.0]
[ruby-core:66414]

Description

(From git commit f5063b7ea7e774519602f7a112d9acf536a1da33 of 22 November 2014.)

In io.c in the following function:

static VALUE
pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convconfig)

IF !defined(HAVE_WORKING_FORK) and !defined(HAVE_SPAWNV), THEN argc and argv are declared. (lines 5938, 5939)

Unless I'm missing something in the #if #else #endif fiesta, they don't seem to be initialized anywhere.

Then in the #else case at line 6069, we have this:

#else
    if (argc) {
	prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
	cmd = StringValueCStr(prog);
    }

Best case, the compiler initializes argc to 0, which means this is dead code. Worst case, the compiler chooses not to initialize to 0, then Bad Things will happen.

Updated by normalperson (Eric Wong) almost 11 years ago Actions #1 [ruby-core:66419]

wrote:

IF !defined(HAVE_WORKING_FORK) and !defined(HAVE_SPAWNV), THEN argc
and argv are declared. (lines 5938, 5939)
Unless I'm missing something in the #if #else #endif fiesta, they
don't seem to be initialized anywhere.

I concur. On the other hand, which platforms are affected by this
problem? Any platform maintainers care to comment? Maybe we can
drop the code :)

A side note: we'd be better off reimplementing pipe_open (and similar
functions) individually on a per-platform basis to avoid the ugly
CPP conditionals.

Right now, it's hard-to-read for every platform. Of course, this split
requires much coordination between platform maintainers...

Updated by jeremyevans0 (Jeremy Evans) over 6 years ago Actions #2 [ruby-core:93623]

  • Status changed from Open to Closed

I believe this issue was fixed by aa107497cd379b713eba8cecdb9a882bb1e0dd89, which removed the argc and argv variables in favor of using rb_execarg_commandline(eargp, &prog), and eargp and prog are always initialized.

Actions

Also available in: PDF Atom