From c67008b6a807cb7227f1c62735aa1e792b4de60f Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Mon, 30 Nov 2015 12:28:59 -0800 Subject: [PATCH] minor fault injection tag rework for fko_set_rand_value() and fko_set_username() --- lib/fko_user.c | 5 +--- test/fko-wrapper/fko_fault_injection.c | 33 ++++++++++++++++++++++---- test/fko-wrapper/fko_wrapper.c | 3 ++- test/test-fwknop.pl | 20 ++++++++++++++++ 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/lib/fko_user.c b/lib/fko_user.c index 969e532d..ca6d5460 100644 --- a/lib/fko_user.c +++ b/lib/fko_user.c @@ -82,9 +82,6 @@ fko_set_username(fko_ctx_t ctx, const char * const spoof_user) { if((username = getenv("USER")) == NULL) { -#if HAVE_LIBFIU - fiu_return_on("fko_set_username_strdup1", FKO_ERROR_MEMORY_ALLOCATION); -#endif username = strdup("NO_USER"); if(username == NULL) return(FKO_ERROR_MEMORY_ALLOCATION); @@ -116,7 +113,7 @@ fko_set_username(fko_ctx_t ctx, const char * const spoof_user) free(ctx->username); #if HAVE_LIBFIU - fiu_return_on("fko_set_username_strdup2", FKO_ERROR_MEMORY_ALLOCATION); + fiu_return_on("fko_set_username_strdup", FKO_ERROR_MEMORY_ALLOCATION); #endif ctx->username = strdup(username); diff --git a/test/fko-wrapper/fko_fault_injection.c b/test/fko-wrapper/fko_fault_injection.c index 42246f48..5071ece2 100644 --- a/test/fko-wrapper/fko_fault_injection.c +++ b/test/fko-wrapper/fko_fault_injection.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "fko.h" @@ -13,9 +14,8 @@ const char *fiu_tags[] = { "fko_set_rand_value_calloc1", "fko_set_rand_value_calloc2", "fko_set_username_init", - "fko_set_username_strdup1", "fko_set_username_valuser", - "fko_set_username_strdup2", + "fko_set_username_strdup", "fko_set_timestamp_init", "fko_set_timestamp_val", "set_spa_digest_type_init", @@ -36,7 +36,6 @@ const int fiu_rvs[] = { FKO_ERROR_MEMORY_ALLOCATION, FKO_ERROR_MEMORY_ALLOCATION, FKO_ERROR_CTX_NOT_INITIALIZED, - FKO_ERROR_MEMORY_ALLOCATION, FKO_ERROR_INVALID_DATA, FKO_ERROR_MEMORY_ALLOCATION, FKO_ERROR_CTX_NOT_INITIALIZED, @@ -53,25 +52,49 @@ const int fiu_rvs[] = { int main(void) { fko_ctx_t ctx = NULL; - int res = 0, i; + int res = 0, i, es = EXIT_SUCCESS; + int exec=0, success=0, fail=0; fiu_init(0); for (i=0; i < sizeof(fiu_rvs)/sizeof(int); i++) { + exec++; printf("[+] libfiu injection tag: %s\n", fiu_tags[i]); fiu_enable(fiu_tags[i], fiu_rvs[i], NULL, 0); res = fko_new(&ctx); + + if(strncmp(fiu_tags[i], "fko_set_rand_value_lenval", + strlen("fko_set_rand_value_lenval")) == 0) + res = fko_set_rand_value(ctx, "asdf1234"); + + if(strncmp(fiu_tags[i], "fko_set_rand_value_strdup", + strlen("fko_set_rand_value_strdup")) == 0) + res = fko_set_rand_value(ctx, "asdf1234"); + + if(strncmp(fiu_tags[i], "fko_set_username_valuser", + strlen("fko_set_username_valuser")) == 0) + res = fko_set_username(ctx, "BADCHAR="); + if (res == FKO_SUCCESS) + { printf("[-] fko_new(): %s\n", fko_errstr(res)); + fail++; + es = EXIT_FAILURE; + } else + { printf("[+] fko_new(): %s\n", fko_errstr(res)); + success++; + } fko_destroy(ctx); ctx = NULL; fiu_disable(fiu_tags[i]); } - return 0; + printf("fiu_fault_injection() passed/failed/executed: %d/%d/%d\n", + success, fail, exec); + return es; } diff --git a/test/fko-wrapper/fko_wrapper.c b/test/fko-wrapper/fko_wrapper.c index ebddcae7..2b2332ef 100644 --- a/test/fko-wrapper/fko_wrapper.c +++ b/test/fko-wrapper/fko_wrapper.c @@ -460,8 +460,9 @@ test_loop(int new_ctx_flag, int destroy_ctx_flag) ctx_update(&ctx, new_ctx_flag, destroy_ctx_flag, DO_PRINT); } - /* NULL tests */ + /* (mostly) NULL tests */ fko_set_rand_value(ctx, NULL); + fko_set_rand_value(ctx, "asdf1234"); fko_set_rand_value(ctx, NULL); fko_set_username(ctx, NULL); fko_set_username(ctx, NULL); diff --git a/test/test-fwknop.pl b/test/test-fwknop.pl index 06c13003..42447576 100755 --- a/test/test-fwknop.pl +++ b/test/test-fwknop.pl @@ -1568,6 +1568,26 @@ sub fault_injection_tag() { my $fw_rule_created = 0; my $fw_rule_removed = 0; + my $tag_name = ''; + if ($test_hr->{'cmdline'}) { + if ($test_hr->{'cmdline'} =~ /fault\-injection\-tag\s(S+)/) { + $tag_name = $1; + } + } elsif ($test_hr->{'fwknopd_cmdline'}) { + if ($test_hr->{'fwknopd_cmdline'} =~ /fault\-injection\-tag\s(S+)/) { + $tag_name = $1; + } + } + + if ($tag_name) { + unless ($test_hr->{'detail'} =~ /\s$tag_name/) { + &write_test_file( + "[-] tag_name '$tag_name' not in test message.\n", + $curr_test_file); + return 0; + } + } + if ($test_hr->{'pkt'} or ($test_hr->{'cmdline'} and $test_hr->{'fwknopd_cmdline'})) {