static pigsty_entry_ctx *load_signatures(const char *signatures) { pigsty_entry_ctx *sig_entries = NULL; const char *sp = NULL; char curr_file_path[8192] = ""; char *cfp = NULL; sp = signatures; cfp = &curr_file_path[0]; while (*sp != 0) { if (*sp != ',' && *(sp + 1) != 0) { *cfp = *sp; cfp++; } else { if (*(sp + 1) == 0) { if (*sp != ',') { *cfp = *sp; cfp++; } } *cfp = '\0'; if (!should_be_quiet) { printf("pig INFO: loading \"%s\"...\n", curr_file_path); } sig_entries = load_pigsty_data_from_file(sig_entries, curr_file_path); if (sig_entries == NULL) { if (!should_be_quiet) { printf("pig INFO: load failure.\n"); } break; } if (!should_be_quiet) { printf("pig INFO: load success.\n"); } cfp = &curr_file_path[0]; } sp++; } return sig_entries; }
int retval = 0; size_t dsize = 0; if (fp == NULL) { return 0; } dsize = strlen(data); retval = (fwrite(data, dsize, 1, fp) > -1); fclose(fp); return retval; } CUTE_TEST_CASE(pigsty_file_parsing_tests) pigsty_entry_ctx *pigsty = NULL; char *test_pigsty = "[ ip.version = 4, ip.tos = 5, ip.src = 127.900.0.1 ]"; // invalid ip octect. write_to_file("test.pigsty", test_pigsty); pigsty = load_pigsty_data_from_file(pigsty, "test.pigsty"); CUTE_CHECK("pigsty != NULL", pigsty == NULL); remove("test.pigsty"); test_pigsty = "[ ip.version = 4, ip.tos = 5, ip.src = 127.0.0.0.1 ]"; // invalid ip with more octects than expected. write_to_file("test.pigsty", test_pigsty); pigsty = load_pigsty_data_from_file(pigsty, "test.pigsty"); CUTE_CHECK("pigsty != NULL", pigsty == NULL); remove("test.pigsty"); test_pigsty = "[ ip.version = 4x0, ip.tos = 5, ip.src = 127.0.0.1 ]"; // invalid ip version. write_to_file("test.pigsty", test_pigsty); pigsty = load_pigsty_data_from_file(pigsty, "test.pigsty"); CUTE_CHECK("pigsty != NULL", pigsty == NULL); remove("test.pigsty");