From 5f227cfa488e28bba60376e7f10c387cc0c3f9c5 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Sat, 24 May 2014 14:47:10 -0400 Subject: [PATCH] [libfko] added fault injections for fko_set_username() --- lib/fko_user.c | 14 ++++++++++++++ test/fko-wrapper/fko_fault_injection.c | 13 ++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/fko_user.c b/lib/fko_user.c index 99b8086d..0bceb9de 100644 --- a/lib/fko_user.c +++ b/lib/fko_user.c @@ -43,6 +43,10 @@ fko_set_username(fko_ctx_t ctx, const char * const spoof_user) char *username = NULL; int res = FKO_SUCCESS, is_user_heap_allocated=0; +#if HAVE_LIBFIU + fiu_return_on("fko_set_username_init", FKO_ERROR_CTX_NOT_INITIALIZED); +#endif + /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) @@ -78,6 +82,9 @@ 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); @@ -96,6 +103,9 @@ fko_set_username(fko_ctx_t ctx, const char * const spoof_user) { if(is_user_heap_allocated == 1) free(username); +#if HAVE_LIBFIU + fiu_return_on("fko_set_username_valuser", FKO_ERROR_INVALID_DATA); +#endif return res; } @@ -105,6 +115,10 @@ fko_set_username(fko_ctx_t ctx, const char * const spoof_user) if(ctx->username != NULL) free(ctx->username); +#if HAVE_LIBFIU + fiu_return_on("fko_set_username_strdup2", FKO_ERROR_MEMORY_ALLOCATION); +#endif + ctx->username = strdup(username); ctx->state |= FKO_DATA_MODIFIED; diff --git a/test/fko-wrapper/fko_fault_injection.c b/test/fko-wrapper/fko_fault_injection.c index 6c32548a..b2d137b7 100644 --- a/test/fko-wrapper/fko_fault_injection.c +++ b/test/fko-wrapper/fko_fault_injection.c @@ -12,7 +12,11 @@ const char *fiu_tags[] = { "fko_set_rand_value_strdup", "fko_set_rand_value_read", "fko_set_rand_value_calloc1", - "fko_set_rand_value_calloc2" + "fko_set_rand_value_calloc2", + "fko_set_username_init", + "fko_set_username_strdup1", + "fko_set_username_valuser", + "fko_set_username_strdup2" }; const int fiu_rvs[] = { FKO_ERROR_MEMORY_ALLOCATION, @@ -22,9 +26,12 @@ const int fiu_rvs[] = { FKO_ERROR_MEMORY_ALLOCATION, FKO_ERROR_FILESYSTEM_OPERATION, 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 }; -const int num_fiu_tags = 8; int main(void) { fko_ctx_t ctx = NULL; @@ -32,7 +39,7 @@ int main(void) { fiu_init(0); - for (i=0; i < num_fiu_tags; i++) { + for (i=0; i < sizeof(fiu_rvs)/sizeof(int); i++) { printf("[+] libfiu injection tag: %s\n", fiu_tags[i]); fiu_enable(fiu_tags[i], fiu_rvs[i], NULL, 0);