Project

General

Profile

Bug #1472

rb_f_syscall converts string value to null terminated c string, but syscall structs can contain nulls.

Added by JohnCarter (John Carter) over 10 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-linux]
[ruby-core:23460]

Description

=begin
The following snippet invokes the statfs64 syscall.
bug.rb================================================================
string = " "* 84
p syscall( 268, "/", string.size, string)
string = "\0"* 84
p syscall( 268, "/", string.size, string)
======================================================================

If I run this under ruby 1.8.6, both invocations work.

If I run this under ruby 1.8.7, the second one fails with...
ruby -w bug.rb
0
bug.rb:4:in `syscall': string contains null byte (ArgumentError)
from bug.rb:4

The reason is in ruby-1.8.7-p22/io.c in the function rb_f_syscall
there is this code....

if (!NIL_P(v)) {
    StringValue(v);
    rb_str_modify(v);
    arg[i] = (unsigned long)StringValueCStr(v);
}

In ruby 1.8.6 is was

if (!NIL_P(v)) {
    StringValue(v);
    rb_str_modify(v);
    arg[i] = (unsigned long)RSTRING(v)->ptr;
}

The macro StringValueCStr is defined in ruby.h as....
#define StringValueCStr(v) rb_string_value_cstr(&(v))

The function rb_string_value_cstr is defined in string.c as ....

rb_string_value_cstr(ptr)
volatile VALUE *ptr;
{
VALUE str = rb_string_value(ptr);
char *s = RSTRING(str)->ptr;

 if (!s || RSTRING(str)->len != strlen(s)) {
rb_raise(rb_eArgError, "string contains null byte");
 }
 return s;

}

I believe the original 1.8.6 implementation was correct and this
particular changed should be rolled back.

Thanks.

http://rubyforge.org/tracker/index.php?func=detail&aid=20895&group_id=426&atid=1698

Applies to 1.8.7 and 1.9.1 p 129
=end


Files

ruby_1_8_7_io_syscall.patch (345 Bytes) ruby_1_8_7_io_syscall.patch patch JohnCarter (John Carter), 05/15/2009 05:41 PM

Associated revisions

Revision f12003d3
Added by a_matsuda almost 3 years ago

Update documentation of fetch

The sentence Negative values of +index+ count from the end of the array. can be interpreted that it only holds if a block is given. Clarify it.

Patch by: Lukas Elmer lukas.elmer@gmail.com (lukaselmer (Lukas Elmer))
Signed-off-by: Akira Matsuda ronnie@dio.jp

closes #1472
[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 56679
Added by a_matsuda almost 3 years ago

Update documentation of fetch

The sentence Negative values of +index+ count from the end of the array. can be interpreted that it only holds if a block is given. Clarify it.

Patch by: Lukas Elmer lukas.elmer@gmail.com (lukaselmer (Lukas Elmer))
Signed-off-by: Akira Matsuda ronnie@dio.jp

closes #1472
[ci skip]

Revision 56679
Added by a_matsuda almost 3 years ago

Update documentation of fetch

The sentence Negative values of +index+ count from the end of the array. can be interpreted that it only holds if a block is given. Clarify it.

Patch by: Lukas Elmer lukas.elmer@gmail.com (lukaselmer (Lukas Elmer))
Signed-off-by: Akira Matsuda ronnie@dio.jp

closes #1472
[ci skip]

Revision 56679
Added by a_matsuda almost 3 years ago

Update documentation of fetch

The sentence Negative values of +index+ count from the end of the array. can be interpreted that it only holds if a block is given. Clarify it.

Patch by: Lukas Elmer lukas.elmer@gmail.com (lukaselmer (Lukas Elmer))
Signed-off-by: Akira Matsuda ronnie@dio.jp

closes #1472
[ci skip]

Revision 56679
Added by a_matsuda almost 3 years ago

Update documentation of fetch

The sentence Negative values of +index+ count from the end of the array. can be interpreted that it only holds if a block is given. Clarify it.

Patch by: Lukas Elmer lukas.elmer@gmail.com (lukaselmer (Lukas Elmer))
Signed-off-by: Akira Matsuda ronnie@dio.jp

closes #1472
[ci skip]

History

#1

Updated by shyouhei (Shyouhei Urabe) almost 10 years ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

=begin

=end

#2

Updated by JohnCarter (John Carter) over 9 years ago

=begin
Still present in..

ruby-1.8.7-p249.tar.bz2
ruby-1.9.1-p378.tar.bz2

=end

#3

Updated by Anonymous almost 3 years ago

  • Status changed from Assigned to Closed

Applied in changeset ruby-trunk:r56679.


Update documentation of fetch

The sentence Negative values of +index+ count from the end of the array. can be interpreted that it only holds if a block is given. Clarify it.

Patch by: Lukas Elmer lukas.elmer@gmail.com (lukaselmer (Lukas Elmer))
Signed-off-by: Akira Matsuda ronnie@dio.jp

closes #1472
[ci skip]

Also available in: Atom PDF