/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include "secutil.h" #include "nss.h" #include "certt.h" #include "keyhi.h" #include "pk11pub.h" #define MAX_TEST_SIZE 0xA00000 // 10 MBs should be TONS! #define PERSIST_MAX 10000 unsigned int persist_cnt = 0; const SEC_ASN1Template OCTET_STRING_Template[] = { { SEC_ASN1_OCTET_STRING, 0 }, { 0 } }; int main(int argc, char** argv) { FILE *fp; PLArenaPool* temparena = NULL; SECItem data = { siBuffer, NULL, 0 }; SECItem output; unsigned int length = 0; unsigned char *bytes = NULL; if (argc < 2) { printf("Missing test case name!\n"); return 1; } try_again: temparena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); if (!temparena) { printf("PORT_NewArena failed!\n"); return 1; } fp = fopen(argv[1], "rb"); if (fp == NULL) { printf("fopen failed!\n"); return 1; } fseek(fp, 0, SEEK_END); length = ftell(fp); if (length > MAX_TEST_SIZE) { fclose(fp); printf("test case too large!\n"); return 1; } bytes = (unsigned char *)malloc(length); if (bytes == NULL) { fclose(fp); printf("failed to malloc bytes\n"); return 1; } fseek(fp , 0, SEEK_SET); fread(bytes, 1, length, fp); fclose(fp); memset(&output, 0, sizeof(SECItem)); data.type = siBuffer; data.data = bytes; data.len = length; if (SEC_ASN1DecodeItem(temparena, &output, OCTET_STRING_Template, &data) != SECSuccess) { printf("SEC_ASN1DecodeItem failed!\n"); } if (bytes != NULL) { free(bytes); bytes = NULL; } if (temparena != NULL) { PORT_FreeArena(temparena, PR_FALSE); temparena = NULL; } if (getenv("AFL_PERSISTENT") && persist_cnt++ < PERSIST_MAX) { raise(SIGSTOP); goto try_again; } printf("Done\n"); return 0; }