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
a38f8fe6
Commit
a38f8fe6
authored
May 13, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support comments in user-input; also add checks for buffer overflow
parent
4e357a49
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+19
-6
No files found.
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
View file @
a38f8fe6
...
...
@@ -100,9 +100,9 @@ is_code_block_open(struct mrb_parser_state *parser)
/* all states which need more code */
case
EXPR_BEG
:
/*
an expression was just started
, */
/*
we can't end it like this
*/
code_block_open
=
TRU
E
;
/*
beginning of a statement
, */
/*
that means previous line ended
*/
;;
code_block_open
=
FALS
E
;
break
;
case
EXPR_DOT
:
/* a message dot was the last token, */
...
...
@@ -319,6 +319,10 @@ main(int argc, char **argv)
char_index
=
0
;
while
((
last_char
=
getchar
())
!=
'\n'
)
{
if
(
last_char
==
EOF
)
break
;
if
(
char_index
>
sizeof
(
last_code_line
)
-
2
)
{
fputs
(
"input string too long
\n
"
,
stderr
);
continue
;
}
last_code_line
[
char_index
++
]
=
last_char
;
}
if
(
last_char
==
EOF
)
{
...
...
@@ -326,6 +330,7 @@ main(int argc, char **argv)
break
;
}
last_code_line
[
char_index
++
]
=
'\n'
;
last_code_line
[
char_index
]
=
'\0'
;
#else
char
*
line
=
MIRB_READLINE
(
code_block_open
?
"* "
:
"> "
);
...
...
@@ -333,14 +338,22 @@ main(int argc, char **argv)
printf
(
"
\n
"
);
break
;
}
strncpy
(
last_code_line
,
line
,
sizeof
(
last_code_line
)
-
1
);
if
(
strlen
(
line
)
>
sizeof
(
last_code_line
)
-
2
)
{
fputs
(
"input string too long
\n
"
,
stderr
);
continue
;
}
strcpy
(
last_code_line
,
line
);
strcat
(
last_code_line
,
"
\n
"
);
MIRB_ADD_HISTORY
(
line
);
free
(
line
);
#endif
if
(
code_block_open
)
{
strcat
(
ruby_code
,
"
\n
"
);
strcat
(
ruby_code
,
last_code_line
);
if
(
strlen
(
ruby_code
)
+
strlen
(
last_code_line
)
>
sizeof
(
ruby_code
)
-
1
)
{
fputs
(
"concatenated input string too long
\n
"
,
stderr
);
continue
;
}
strcat
(
ruby_code
,
last_code_line
);
}
else
{
if
((
strcmp
(
last_code_line
,
"quit"
)
==
0
)
||
(
strcmp
(
last_code_line
,
"exit"
)
==
0
))
{
...
...
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