[libfko] started on libfiu fault injection code

This commit is contained in:
Michael Rash
2014-05-24 10:14:28 -04:00
parent 8d61a8cf7f
commit 35ad832392
3 changed files with 37 additions and 19 deletions

View File

@@ -35,6 +35,10 @@
#include "config.h"
#endif
#if HAVE_LIBFIU
#include <fiu-local.h>
#endif
#include <stdio.h>
#include <sys/types.h>

View File

@@ -43,6 +43,10 @@ fko_new(fko_ctx_t *r_ctx)
int res;
char *ver;
#if HAVE_LIBFIU
fiu_return_on("fko_new_calloc", FKO_ERROR_MEMORY_ALLOCATION);
#endif
ctx = calloc(1, sizeof *ctx);
if(ctx == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);
@@ -59,6 +63,11 @@ fko_new(fko_ctx_t *r_ctx)
/* Set the version string.
*/
ctx->initval = FKO_CTX_INITIALIZED;
#if HAVE_LIBFIU
fiu_return_on("fko_new_strdup", FKO_ERROR_MEMORY_ALLOCATION);
#endif
ver = strdup(FKO_PROTOCOL_VERSION);
ctx->initval = 0;
if(ver == NULL)

View File

@@ -4,31 +4,36 @@
#include <fiu-control.h>
#include "fko.h"
const char *fiu_tags[] = {
"fko_new_calloc",
"fko_new_strdup"
};
const int fiu_rvs[] = {
FKO_ERROR_MEMORY_ALLOCATION,
FKO_ERROR_MEMORY_ALLOCATION
};
const int num_fiu_tags = 2;
int main(void) {
fko_ctx_t ctx = NULL;
int res = 0;
int res = 0, i;
fiu_init(0);
if (0) {
fiu_enable("fko_strdup1", FKO_ERROR_MEMORY_ALLOCATION, NULL, 0);
res = fko_new(&ctx);
if (res == FKO_SUCCESS)
printf("[-] fko_new(): %s\n", fko_errstr(res));
else
printf("[+] fko_new(): %s\n", fko_errstr(res));
fko_destroy(ctx);
fiu_disable("fko_strdup1");
}
for (i=0; i < num_fiu_tags; i++) {
printf("[+] libfiu injection tag: %s\n", fiu_tags[i]);
fiu_enable("fko_set_rand_value1", FKO_ERROR_MEMORY_ALLOCATION, NULL, 0);
res = fko_new(&ctx);
if (res == FKO_SUCCESS)
printf("[-] fko_new(): %s\n", fko_errstr(res));
else
printf("[+] fko_new(): %s\n", fko_errstr(res));
fko_destroy(ctx);
fiu_disable("fko_set_rand_value1");
fiu_enable(fiu_tags[i], fiu_rvs[i], NULL, 0);
res = fko_new(&ctx);
if (res == FKO_SUCCESS)
printf("[-] fko_new(): %s\n", fko_errstr(res));
else
printf("[+] fko_new(): %s\n", fko_errstr(res));
fko_destroy(ctx);
fiu_disable(fiu_tags[i]);
}
return 0;
}