Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
c91c9e24
Unverified
Commit
c91c9e24
authored
Apr 15, 2020
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Apr 15, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4968 from dearblue/check-fd
Check the file descriptor with `IO#initialize`; resolve #4966
parents
7add5240
3c03385e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
mrbgems/mruby-io/src/io.c
mrbgems/mruby-io/src/io.c
+38
-0
mrbgems/mruby-io/test/io.rb
mrbgems/mruby-io/test/io.rb
+4
-0
No files found.
mrbgems/mruby-io/src/io.c
View file @
c91c9e24
...
...
@@ -645,6 +645,43 @@ mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
return
copy
;
}
static
void
check_file_descriptor
(
mrb_state
*
mrb
,
mrb_int
fd
)
{
struct
stat
sb
;
int
fdi
=
(
int
)
fd
;
#if MRB_INT_MIN < INT_MIN || MRB_INT_MAX > INT_MAX
if
(
fdi
!=
fd
)
{
goto
badfd
;
}
#endif
#ifdef _WIN32
{
DWORD
err
;
int
len
=
sizeof
(
err
);
if
(
getsockopt
(
fdi
,
SOL_SOCKET
,
SO_ERROR
,
(
char
*
)
&
err
,
&
len
)
==
0
)
{
return
;
}
}
if
(
fdi
<
0
||
fdi
>
_getmaxstdio
())
{
goto
badfd
;
}
#endif
/* _WIN32 */
if
(
fstat
(
fdi
,
&
sb
)
!=
0
)
{
goto
badfd
;
}
return
;
badfd:
mrb_sys_fail
(
mrb
,
"bad file descriptor"
);
}
mrb_value
mrb_io_initialize
(
mrb_state
*
mrb
,
mrb_value
io
)
{
...
...
@@ -656,6 +693,7 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
mode
=
opt
=
mrb_nil_value
();
mrb_get_args
(
mrb
,
"i|oo"
,
&
fd
,
&
mode
,
&
opt
);
check_file_descriptor
(
mrb
,
fd
);
if
(
mrb_nil_p
(
mode
))
{
mode
=
mrb_str_new_cstr
(
mrb
,
"r"
);
}
...
...
mrbgems/mruby-io/test/io.rb
View file @
c91c9e24
...
...
@@ -24,6 +24,10 @@ def assert_io_open(meth)
end
end
io2
.
close
unless
meth
==
:open
assert_raise
(
RuntimeError
)
{
IO
.
__send__
(
meth
,
1023
)
}
# For Windows
assert_raise
(
RuntimeError
)
{
IO
.
__send__
(
meth
,
1
<<
26
)
}
assert_raise
(
RuntimeError
)
{
IO
.
__send__
(
meth
,
1
<<
32
)
}
if
(
1
<<
32
).
kind_of?
(
Integer
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment