Skip to content

Commit

Permalink
Fix Command out-of-bounds segfault. Close #10.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabordemooij committed Jan 28, 2016
1 parent 344da4a commit de44cb9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ctr_object* ctr_shell_call(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* ctr_command_argument(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* numberObject = ctr_internal_cast2number(argumentList->object);
int n = (int) numberObject->value.nvalue;
if (n >= ctr_argc) return CtrStdNil;
if (n >= ctr_argc || n < 0) return CtrStdNil;
return ctr_build_string(ctr_argv[n], strlen(ctr_argv[n]));
}

Expand Down
7 changes: 7 additions & 0 deletions tests/test0116.ctr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Command argument should segfault when out-of-bounds, issue#10
wrong := Command argument: -10.
(wrong = Nil) ifTrue: {\
Pen write: 'I can handle out-of-bound Command arguments.\n'.
}, else: {\
Pen write: 'Fail\n'.
}.
1 change: 1 addition & 0 deletions tests/test0116.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I can handle out-of-bound Command arguments.

0 comments on commit de44cb9

Please sign in to comment.