diff --git a/common/fko_util.c b/common/fko_util.c index 07aa18ed..4b293163 100644 --- a/common/fko_util.c +++ b/common/fko_util.c @@ -1142,11 +1142,9 @@ count_characters(const char *str, const char match, int len) { int i, count = 0; - for (i=0; i < len; i++) { + for (i=0; i < len && str[i] != '\0'; i++) { if (str[i] == match) count++; - if (str[i] == '\0') - return count; } return count; } diff --git a/test/tests/basic_operations.pl b/test/tests/basic_operations.pl index a50a1baf..3b909d55 100644 --- a/test/tests/basic_operations.pl +++ b/test/tests/basic_operations.pl @@ -192,6 +192,27 @@ 'exec_err' => $YES, 'cmdline' => "$fwknopCmd -A tcp/600001 -a $fake_ip -D $loopback_ip", }, + + ### trigger strtol() error + { + 'category' => 'basic operations', + 'subcategory' => 'client', + 'detail' => 'invalid SPA destination port (1)', + 'function' => \&generic_exec, + 'exec_err' => $YES, + 'cmdline' => "$fwknopCmd -A tcp/22 -a $fake_ip -D $loopback_ip -p 9999999999999999999999999999999999999999999999999999999999", + }, + + ### trigger MAX_PORT error + { + 'category' => 'basic operations', + 'subcategory' => 'client', + 'detail' => 'invalid SPA destination port (2)', + 'function' => \&generic_exec, + 'exec_err' => $YES, + 'cmdline' => "$fwknopCmd -A tcp/22 -a $fake_ip -D $loopback_ip -p 99999", + }, + { 'category' => 'basic operations', 'subcategory' => 'client',