static void enable_fault_injections(fko_cli_options_t * const opts) { if(opts->fault_injection_tag[0] != 0x0) { fiu_init(0); fiu_enable(opts->fault_injection_tag, 1, NULL, 0); } return; }
int main(void) { fko_ctx_t ctx = NULL; 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(strncmp(fiu_tags[i], "fko_set_username_strdup", strlen("fko_set_username_strdup")) == 0) res = fko_set_username(ctx, "normaluser"); 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]); } printf("fiu_fault_injection() passed/failed/executed: %d/%d/%d\n", success, fail, exec); return es; }
static void enable_fault_injections(fko_srv_options_t * const opts) { if(opts->config[CONF_FAULT_INJECTION_TAG] != NULL) { if(opts->verbose) log_msg(LOG_INFO, "Enable fault injection tag: %s", opts->config[CONF_FAULT_INJECTION_TAG]); if(fiu_init(0) != 0) { fprintf(stderr, "[*] Could not enable fault injection tag: %s\n", opts->config[CONF_FAULT_INJECTION_TAG]); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } if (fiu_enable(opts->config[CONF_FAULT_INJECTION_TAG], 1, NULL, 0) != 0) { fprintf(stderr, "[*] Could not enable fault injection tag: %s\n", opts->config[CONF_FAULT_INJECTION_TAG]); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } } return; }
static int enable_fault_injections(fko_cli_options_t * const opts) { int rv = 1; if(opts->fault_injection_tag[0] != 0x0) { if(opts->verbose) log_msg(LOG_VERBOSITY_NORMAL, "[+] Enable fault injection tag: %s", opts->fault_injection_tag); if(fiu_init(0) != 0) { log_msg(LOG_VERBOSITY_WARNING, "[*] Unable to set fault injection tag: %s", opts->fault_injection_tag); rv = 0; } if(fiu_enable(opts->fault_injection_tag, 1, NULL, 0) != 0) { log_msg(LOG_VERBOSITY_WARNING, "[*] Unable to set fault injection tag: %s", opts->fault_injection_tag); rv = 0; } } return rv; }