Skip to content

Commit

Permalink
* file.c (file_expand_path): call rb_str_set_len before BUFCHECK to
Browse files Browse the repository at this point in the history
  prevent rb_str_resize in BUFCHECK discard the content.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed Apr 30, 2010
1 parent 479fa40 commit c41dc08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Fri Apr 30 12:05:20 2010 Tanaka Akira <akr@fsij.org>

* file.c (file_expand_path): call rb_str_set_len before BUFCHECK to
prevent rb_str_resize in BUFCHECK discard the content.

Fri Apr 30 11:48:31 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>

* string.c (rb_str_sub_bang): String#sub! now raises an error when
Expand Down
4 changes: 4 additions & 0 deletions file.c
Expand Up @@ -2858,10 +2858,12 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result)
if (p > buf && p[-1] == '/')
--p;
else {
rb_str_set_len(result, p-buf);
BUFCHECK(bdiff + 1 >= buflen);
*p = '/';
}

rb_str_set_len(result, p-buf+1);
BUFCHECK(bdiff + 1 >= buflen);
p[1] = 0;
root = skipprefix(buf);
Expand Down Expand Up @@ -2925,6 +2927,7 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result)
#endif
if (s > b) {
long rootdiff = root - buf;
rb_str_set_len(result, p-buf+1);
BUFCHECK(bdiff + (s-b+1) >= buflen);
root = buf + rootdiff;
memcpy(++p, b, s-b);
Expand Down Expand Up @@ -2955,6 +2958,7 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result)
}
}
#endif
rb_str_set_len(result, p-buf+1);
BUFCHECK(bdiff + (s-b) >= buflen);
memcpy(++p, b, s-b);
p += s-b;
Expand Down

0 comments on commit c41dc08

Please sign in to comment.