Skip to content

Commit 69d8b47

Browse files
committed
Fix range check crash issues
1 parent 09b41b0 commit 69d8b47

File tree

8 files changed

+26
-11
lines changed

8 files changed

+26
-11
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [0.12.14])
10+
AC_INIT([smallbasic], [0.12.15])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
smallbasic (0.12.15) unstable; urgency=low
2+
* Various see web site
3+
4+
-- Chris Warren-Smith <cwarrensmith@gmail.com> Fri, 28 Dec 2018 09:45:25 +1000
5+
16
smallbasic (0.12.14) unstable; urgency=low
27
* Various see web site
38

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REM Don't crash when label does not exist
2+
goto 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
* COMP-ERROR AT Main:2 *
4+
Description:
5+
Label '1' is not defined
6+

src/common/scan.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,7 +3401,7 @@ void comp_pass2_scan() {
34013401
w = label->ip;
34023402

34033403
// adjust the address to compensate for optimisation to remove adjoining kwEOC
3404-
if (comp_prog.ptr[w] != kwTYPE_LINE && comp_prog.ptr[w - 1] == kwTYPE_LINE) {
3404+
if (w > 0 && w < comp_prog.count && comp_prog.ptr[w] != kwTYPE_LINE && comp_prog.ptr[w - 1] == kwTYPE_LINE) {
34053405
w--;
34063406
}
34073407
memcpy(comp_prog.ptr + node->pos + (j * ADDRSZ) + (ADDRSZ + ADDRSZ + 3), &w, ADDRSZ);
@@ -3419,7 +3419,7 @@ void comp_pass2_scan() {
34193419
w = label->ip;
34203420

34213421
// adjust the address to compensate for optimisation to remove adjoining kwEOC
3422-
if (comp_prog.ptr[w] != kwTYPE_LINE && comp_prog.ptr[w - 1] == kwTYPE_LINE) {
3422+
if (w > 0 && w < comp_prog.count && comp_prog.ptr[w] != kwTYPE_LINE && comp_prog.ptr[w - 1] == kwTYPE_LINE) {
34233423
w--;
34243424
}
34253425

@@ -3697,12 +3697,14 @@ bcip_t comp_optimise_line_goto(bcip_t ip) {
36973697

36983698
ip = comp_read_goto(ip + 1, &addr, &level);
36993699
bcip_t goto_ip = addr;
3700-
if (comp_prog.ptr[goto_ip] == kwTYPE_EOC) {
3700+
3701+
// note: INVALID_ADDR is assumed to be > comp_prog.count
3702+
if (goto_ip < comp_prog.count && comp_prog.ptr[goto_ip] == kwTYPE_EOC) {
37013703
new_addr = goto_ip + 1;
37023704
}
3703-
while (goto_ip > 0 && comp_prog.ptr[goto_ip] == kwTYPE_LINE) {
3705+
while (goto_ip > -1 && comp_prog.ptr[goto_ip] == kwTYPE_LINE) {
37043706
goto_ip += 1 + sizeof(bcip_t);
3705-
if (comp_prog.ptr[goto_ip] == kwGOTO) {
3707+
if (goto_ip < comp_prog.count && comp_prog.ptr[goto_ip] == kwGOTO) {
37063708
code_t next_level;
37073709
comp_read_goto(goto_ip + 1, &addr, &next_level);
37083710
goto_ip = addr;

src/platform/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId 'net.sourceforge.smallbasic'
1010
minSdkVersion 16
1111
targetSdkVersion 27
12-
versionCode 31
13-
versionName "0.12.14.2"
12+
versionCode 32
13+
versionName "0.12.15"
1414
resConfigs "en"
1515
}
1616

src/platform/console/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TEST_DIR=../../../samples/distro-examples/tests
2727
UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto \
2828
uds hash pass1 call_tau short-circuit strings stack-test \
2929
replace-test read-data proc optchk letbug ptr \
30-
trycatch chain stream-files split-join sprint all scope
30+
trycatch chain stream-files split-join sprint all scope goto
3131

3232
test: ${bin_PROGRAMS}
3333
@for utest in $(UNIT_TESTS); do \

src/ui/textedit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,15 +1707,15 @@ void TextEditInput::updateScroll() {
17071707

17081708
int TextEditInput::wordEnd() {
17091709
int i = _state.cursor;
1710-
while (IS_VAR_CHAR(_buf._buffer[i]) && i < _buf._len) {
1710+
while (i >= 0 && i < _buf._len && IS_VAR_CHAR(_buf._buffer[i])) {
17111711
i++;
17121712
}
17131713
return i;
17141714
}
17151715

17161716
int TextEditInput::wordStart() {
17171717
int cursor = _state.cursor == 0 ? 0 : _state.cursor - 1;
1718-
return (_buf._buffer[cursor] == '\n' ? _state.cursor :
1718+
return ((cursor >= 0 && cursor < _buf._len && _buf._buffer[cursor] == '\n') ? _state.cursor :
17191719
is_word_boundary(&_buf, _state.cursor) ? _state.cursor :
17201720
stb_textedit_move_to_word_previous(&_buf, _state.cursor));
17211721
}

0 commit comments

Comments
 (0)