BUG: Ruby 1.8.7 - io.c Argument Error in syscall,"string containsnull byte"

Discussion in 'Ruby' started by John Carter, Jun 30, 2008.

  1. John Carter

    John Carter Guest

    I have opened this as bug...
    http://rubyforge.org/tracker/index.php?func=detail&aid=20895&group_id=426&atid=1698


    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 = (unsigned long)StringValueCStr(v);
    }

    In ruby 1.8.6 is was

    if (!NIL_P(v)) {
    StringValue(v);
    rb_str_modify(v);
    arg = (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.



    John Carter Phone : (64)(3) 358 6639
    Tait Electronics Fax : (64)(3) 359 4632
    PO Box 1645 Christchurch Email :
    New Zealand
     
    John Carter, Jun 30, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Keller

    Problem with getpwnam() syscall

    Thomas Keller, Jan 19, 2004, in forum: Perl
    Replies:
    1
    Views:
    1,380
    Joe Smith
    Jan 20, 2004
  2. Basile Starynkevitch [news]

    [ANN] Tracery - a ruby interface to ptrace syscall on linux

    Basile Starynkevitch [news], Jan 29, 2004, in forum: Ruby
    Replies:
    0
    Views:
    123
    Basile Starynkevitch [news]
    Jan 29, 2004
  3. Replies:
    3
    Views:
    137
  4. Andrew Walrond

    [BUG] Kernel#syscall on x86_64 linux

    Andrew Walrond, Sep 9, 2004, in forum: Ruby
    Replies:
    6
    Views:
    124
    Andrew Walrond
    Sep 10, 2004
  5. Daniel KamiÅ?ski

    execve syscall in ruby

    Daniel KamiÅ?ski, Jul 19, 2008, in forum: Ruby
    Replies:
    6
    Views:
    157
    Daniel Kaminski
    Jul 19, 2008
Loading...

Share This Page