Repository navigation
Commit e531cd4
committed
mruby-io, mruby-socket: convert an argument before reading its Integer
Three methods hand mrb_integer() a value that is not known to be an
Integer, so the bits of some other object are read as one:
- IO#ungetbyte takes anything that is not a String as an Integer.
ungetbyte(nil) pushes back "\x00", ungetbyte([0x41]) pushes back a
byte of the Array, and :A or Object.new are accepted too.
- BasicSocket#setsockopt calls mrb_ensure_int_type() on the level and
drops the converted value, then reads the original. A Float level
such as Socket::SOL_SOCKET.to_f becomes an unrelated number and
setsockopt(2) fails with EINVAL.
- IO#gets drops the result of the same conversion for a non-String
first argument, so gets(5.0) raises TypeError ("Float cannot be
converted to String") instead of reading up to 5 bytes.
Use mrb_as_int(), the conversion mrb_get_args() does for "i", in all
three. IO#ungetbyte(nil) now pushes nothing back and returns nil, as it
does in CRuby, and an object that is neither an Integer nor a String
raises TypeError.1 parent d474475 commit e531cd4
4 files changed
Lines changed: 39 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1915 | 1915 | | |
1916 | 1916 | | |
1917 | 1917 | | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
1918 | 1921 | | |
1919 | 1922 | | |
1920 | 1923 | | |
1921 | 1924 | | |
1922 | 1925 | | |
1923 | 1926 | | |
1924 | 1927 | | |
1925 | | - | |
| 1928 | + | |
1926 | 1929 | | |
1927 | 1930 | | |
1928 | 1931 | | |
| |||
2131 | 2134 | | |
2132 | 2135 | | |
2133 | 2136 | | |
2134 | | - | |
2135 | | - | |
| 2137 | + | |
| 2138 | + | |
2136 | 2139 | | |
2137 | 2140 | | |
2138 | 2141 | | |
2139 | | - | |
2140 | | - | |
2141 | | - | |
2142 | 2142 | | |
2143 | 2143 | | |
2144 | 2144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
506 | 526 | | |
507 | 527 | | |
508 | 528 | | |
| |||
577 | 597 | | |
578 | 598 | | |
579 | 599 | | |
| 600 | + | |
| 601 | + | |
580 | 602 | | |
581 | 603 | | |
582 | 604 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
806 | 806 | | |
807 | 807 | | |
808 | 808 | | |
809 | | - | |
810 | | - | |
| 809 | + | |
811 | 810 | | |
812 | 811 | | |
813 | 812 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
0 commit comments