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

**URL:** <https://www.ruby-forum.com/t/bug-ruby-1-8-7-io-c-argument-error-in-syscall-string-contains-null-byte/141720>\
**Category:** Ruby\
**Created:** [June 30, 2008, 3:23am UTC](https://www.ruby-forum.com/t/bug-ruby-1-8-7-io-c-argument-error-in-syscall-string-contains-null-byte/141720 "2008-06-30T03:23:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [June 30, 2008, 3:23am UTC](https://www.ruby-forum.com/t/bug-ruby-1-8-7-io-c-argument-error-in-syscall-string-contains-null-byte/141720/1 "2008-06-30T03:23:37Z")

</div>

I have opened this as bug…  
[http://rubyforge.org/tracker/index.php?func=detail&aid=20895&group\_id=426&atid=1698](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[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.

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand
