[libfko] added fault injections for fko_set_username()

This commit is contained in:
Michael Rash
2014-05-24 14:47:10 -04:00
parent 17f325eceb
commit 5f227cfa48
2 changed files with 24 additions and 3 deletions
+14
View File
@@ -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;
+10 -3
View File
@@ -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);