Skip to content

Commit

Permalink
Don't exit if 'exit' or 'quit' are in quote blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
joequery committed Aug 18, 2012
1 parent 618f25b commit e7b61c6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/mirb/mirb.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,19 @@ main(void)
last_code_line[char_index] = '\0';

if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) {
/*:quit the program */
break;
if (!code_block_open || !parser->sterm){

This comment has been minimized.

Copy link
@monaka

monaka Sep 3, 2012

Contributor

parser is used without initialization. It may cause runtime crash.

This comment has been minimized.

Copy link
@joequery

joequery Sep 3, 2012

Author Contributor

@monaka I don't see a way parser would ever be deferenced without initialization. If the string is "exit", and !code_block_open is true, the condition short circuits and !parser->sterm is not evaluated. If the string is "exit" and the !code_block_open is false (thus code_block_open is true), then we must have gone through an initialization of parser to change the value of code_block_open

This comment has been minimized.

Copy link
@matz

matz Sep 3, 2012

Member

Fixed in dabe3ca. Thank you.

This comment has been minimized.

Copy link
@monaka

monaka Sep 3, 2012

Contributor

@joequery I see what you say and code runs on this version. But it isn't enough robust against future changes.

break;
}
else{
/* count the quit/exit commands as strings if in a quote block */
strcat(ruby_code, "\n");
strcat(ruby_code, last_code_line);
}
}

else {
if (code_block_open) {
strcat(ruby_code, "\n");
strcat(ruby_code, "\n");
strcat(ruby_code, last_code_line);
}
else {
Expand Down

0 comments on commit e7b61c6

Please sign in to comment.