From: Kevin Day Date: Tue, 20 Mar 2012 03:10:50 +0000 (-0500) Subject: Bugfix: add buffer overflow checks X-Git-Tag: 0.3.0~62 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=566afe8ef5b40670e1305456eb74f7cdd41e7cf4;p=fll Bugfix: add buffer overflow checks When I added the input parameter to the write functions I forgot to do buffer size checks now that the input size could be different than the buffer size. --- diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index 1db7f0e..d4c8610 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -300,7 +300,7 @@ extern "C"{ if (buffer.string[input->start] == f_fss_delimit_slash) { f_string_length delimit_slash_count = 0; - while (input->start <= input->stop) { + while (input->start <= input->stop && input->start < buffer.used) { if (buffer.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; @@ -348,7 +348,7 @@ extern "C"{ input->start++; } - while (input->start <= input->stop) { + while (input->start <= input->stop && input->start < buffer.used) { if (buffer.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; @@ -357,11 +357,11 @@ extern "C"{ input->start++; - while (input->start <= input->stop && isspace(buffer.string[input->start])) { + while (input->start <= input->stop && input->start < buffer.used && isspace(buffer.string[input->start])) { input->start++; } // while - if (input->start > input->stop) { + if (input->start > input->stop || input->start >= buffer.used) { object->string[first_space] = f_fss_basic_open; object->used = object_position.stop + 1; break; @@ -374,7 +374,7 @@ extern "C"{ object->string[object_position.stop] = f_fss_delimit_double_quote; object_position.stop++; - while (input->start <= input->stop) { + while (input->start <= input->stop && input->start < buffer.used) { if (buffer.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; @@ -400,7 +400,7 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders(buffer, (*input)); - if (input->start > input->stop) { + if (input->start > input->stop || input->start >= buffer.used) { break; } @@ -478,7 +478,7 @@ extern "C"{ if (f_macro_test_for_allocation_errors(status)) return status; } - while (input->start <= input->stop) { + while (input->start <= input->stop && input->start < buffer.used) { if (buffer.string[input->start] != f_eol && buffer.string[input->start] != f_fss_delimit_placeholder) { content->string[content_position.stop] = buffer.string[input->start]; content_position.stop++; diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index 75b2202..903bc29 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -432,7 +432,7 @@ extern "C"{ if (buffer.string[input->start] == f_fss_delimit_slash) { f_string_length delimit_slash_count = 0; - while (input->start <= input->stop) { + while (input->start <= input->stop && input->start < buffer.used) { if (buffer.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; @@ -480,7 +480,7 @@ extern "C"{ input->start++; } - while (input->start <= input->stop) { + while (input->start <= input->stop && input->start < buffer.used) { if (buffer.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; @@ -489,11 +489,11 @@ extern "C"{ input->start++; - while (input->start <= input->stop && isspace(buffer.string[input->start])) { + while (input->start <= input->stop && input->start < buffer.used && isspace(buffer.string[input->start])) { input->start++; } // while - if (input->start > input->stop) { + if (input->start > input->stop || input->start >= buffer.used) { object->string[first_space] = f_fss_extended_open; object->used = object_position.stop + 1; break; @@ -506,7 +506,7 @@ extern "C"{ object->string[object_position.stop] = f_fss_delimit_double_quote; object_position.stop++; - while (input->start <= input->stop) { + while (input->start <= input->stop && input->start < buffer.used) { if (buffer.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; @@ -532,7 +532,7 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders(buffer, (*input)); - if (input->start > input->stop) { + if (input->start > input->stop || input->start >= buffer.used) { break; }