minor fault injection tag rework for fko_set_rand_value() and fko_set_username()

This commit is contained in:
Michael Rash 2015-11-30 12:28:59 -08:00
parent 343d0b7f44
commit c67008b6a8
4 changed files with 51 additions and 10 deletions

View File

@ -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);

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fiu.h>
#include <fiu-control.h>
#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;
}

View File

@ -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);

View File

@ -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'})) {