Пример #1
0
int main(int argc, char* argv[])
{
    LLVMFuzzerInitialize(&argc, &argv);
    if (argc < 2) {
        return LLVMFuzzerTestOneInput(" ", 1);
    } else {
        int nRet = 0;
        void* buf = NULL;
        int nLen = 0;
        FILE* f = fopen(argv[1], "rb");
        if (!f) {
            fprintf(stderr, "%s does not exist.\n", argv[1]);
            exit(1);
        }
        fseek(f, 0, SEEK_END);
        nLen = (int)ftell(f);
        fseek(f, 0, SEEK_SET);
        buf = malloc(nLen);
        if (!buf) {
            fprintf(stderr, "malloc failed.\n");
            fclose(f);
            exit(1);
        }
        if (fread(buf, nLen, 1, f) != 1) {
            fprintf(stderr, "fread failed.\n");
            fclose(f);
            free(buf);
            exit(1);
        }
        fclose(f);
        nRet = LLVMFuzzerTestOneInput(buf, nLen);
        free(buf);
        return nRet;
    }
}
Пример #2
0
int main(int argc, char* argv[])
{
    if( argc < 2 )
    {
        const char str[] =
            "+proj=longlat +datum=WGS84 +nodefs\n+proj=longlat +datum=WGS84 +nodefs\n2 49";
        int ret = LLVMFuzzerTestOneInput((const uint8_t*)(str), sizeof(str) - 1);
        if( ret )
            return ret;

        const char str2[] =
            "+proj=longlat +datum=WGS84 +nodefs\n+proj=longlat +datum=WGS84 +nodefs\nBINARY_2D:\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF";
        ret = LLVMFuzzerTestOneInput((const uint8_t*)(str2), sizeof(str2) - 1);
        if( ret )
            return ret;

        const char str3[] =
            "+proj=longlat +datum=WGS84 +nodefs\n+proj=longlat +datum=WGS84 +nodefs\nBINARY_3D:\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00";
        ret = LLVMFuzzerTestOneInput((const uint8_t*)(str3), sizeof(str3) - 1);
        if( ret )
            return ret;

        return 0;
    }
    else
    {
        int nRet = 0;
        void* buf = NULL;
        int nLen = 0;
        FILE* f = fopen(argv[1], "rb");
        if( !f )
        {
            fprintf(stderr, "%s does not exist.\n", argv[1]);
            exit(1);
        }
        fseek(f, 0, SEEK_END);
        nLen = (int)ftell(f);
        fseek(f, 0, SEEK_SET);
        buf = malloc(nLen);
        if( !buf )
        {
            fprintf(stderr, "malloc failed.\n");
            fclose(f);
            exit(1);
        }
        fread(buf, nLen, 1, f);
        fclose(f);
        nRet = LLVMFuzzerTestOneInput((const uint8_t*)(buf), nLen);
        free(buf);
        return nRet;
    }
}
Пример #3
0
int main(int argc, char *argv[])
{
	FILE *in = NULL;
	unsigned char *in_buf = NULL;
	uint64_t in_file_size;

	if (argc != 2) {
		fprintf(stderr, "Usage: isal_fuzz_inflate <infile>\n");
		exit(1);
	}
	in = fopen(argv[1], "rb");
	if (!in) {
		fprintf(stderr, "Can't open %s for reading\n", argv[1]);
		exit(1);
	}
	in_file_size = get_filesize(in);
	in_buf = malloc(in_file_size);

	if (in_buf == NULL) {
		fprintf(stderr, "Failed to malloc input and outputs buffers\n");
		exit(1);
	}

	fread(in_buf, 1, in_file_size, in);

	return LLVMFuzzerTestOneInput(in_buf, in_file_size);
}
Пример #4
0
int main(int argc, char **argv) {
  fprintf(stderr, "Running in AFl-fuzz mode\nUsage:\n"
                  "afl-fuzz [afl-flags] %s [N] "
                  "-- run N fuzzing iterations before "
                  "re-spawning the process (default: 1000)\n",
          argv[0]);
  if (LLVMFuzzerInitialize)
    LLVMFuzzerInitialize(&argc, &argv);
  // Do any other expensive one-time initialization here.

  maybe_duplicate_stderr();

  __afl_manual_init();

  int N = 1000;
  if (argc >= 2)
    N = atoi(argv[1]);
  assert(N > 0);
  while (__afl_persistent_loop(N)) {
    ssize_t n_read = read(0, AflInputBuf, kMaxAflInputSize);
    if (n_read > 0) {
      // Copy AflInputBuf into a separate buffer to let asan find buffer
      // overflows. Don't use unique_ptr/etc to avoid extra dependencies.
      uint8_t *copy = new uint8_t[n_read];
      memcpy(copy, AflInputBuf, n_read);
      LLVMFuzzerTestOneInput(copy, n_read);
      delete[] copy;
    }
  }
}
Пример #5
0
int main(int argc, char **argv) {
	int i;

	for (i = 1; i < argc; i++) {
		size_t filesize = GetFileLength(argv[i]);
		FILE *stream = fopen(argv[i], "r");
		unsigned char *text = NULL;
		if (stream == NULL) {
			perror(argv[i]);
			exit(EXIT_FAILURE);
		}

		text = (unsigned char *) malloc(filesize + 1);
		if (text == NULL) {
			espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL);
			exit(EXIT_FAILURE);
		}

		fread(text, 1, filesize, stream);
		text[filesize] = 0;
		fclose(stream);

		LLVMFuzzerTestOneInput(text, filesize);
		free(text);
	}

	return EXIT_SUCCESS;
}
Пример #6
0
int main()
{
    const char szGEOJSON[] = "{ \"type\": \"FeatureCollection\", \"features\":[ { \"type\": \"Feature\", \"properties\": { \"AREA\": 5268.813, \"EAS_ID\": 170, \"PRFEDEA\": \"35043413\" }, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ 479750.6875, 4764702.0 ], [ 479658.59375, 4764670.0 ], [ 479640.09375, 4764721.0 ], [ 479735.90625, 4764752.0 ], [ 479750.6875, 4764702.0 ] ] ] } } ] }";
    LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(szGEOJSON),
                           strlen(szGEOJSON));
    return 0;
}
Пример #7
0
int main(int argc, char** argv) {
	assert(argc > 1);
	FILE *fd = fopen(argv[1], "rb");
	fseek(fd, 0, SEEK_END);
	size_t needed = ftell(fd);
	char * data = malloc(needed);
	rewind(fd);
	fread(data, needed, 1, fd);
	return LLVMFuzzerTestOneInput(data, needed);
}
Пример #8
0
int main(int argc, char **argv) {
  gpr_slice buffer;
  squelch = false;
  leak_check = false;
  GPR_ASSERT(
      GRPC_LOG_IF_ERROR("load_file", grpc_load_file(argv[1], 0, &buffer)));
  LLVMFuzzerTestOneInput(GPR_SLICE_START_PTR(buffer), GPR_SLICE_LENGTH(buffer));
  gpr_slice_unref(buffer);
  return 0;
}
Пример #9
0
int main(int argc, char** argv)
{
    FILE* fp;
    uint8_t* Data;
    size_t Size;

    if (argc != 2)
    {
        return 1;
    }
    // opens the file, get its size, and reads it into a buffer
    fp = fopen(argv[1], "rb");
    if (fp == NULL)
    {
        return 2;
    }
    if (fseek(fp, 0L, SEEK_END) != 0)
    {
        fclose(fp);
        return 2;
    }
    Size = ftell(fp);
    if (Size == (size_t)-1)
    {
        fclose(fp);
        return 2;
    }
    if (fseek(fp, 0L, SEEK_SET) != 0)
    {
        fclose(fp);
        return 2;
    }
    Data = (uint8_t*)malloc(Size);
    if (Data == NULL)
    {
        fclose(fp);
        return 2;
    }
    if (fread(Data, Size, 1, fp) != 1)
    {
        fclose(fp);
        return 2;
    }

    // lauch fuzzer
    LLVMFuzzerTestOneInput(Data, Size);
    fclose(fp);
    return 0;
}
Пример #10
0
int main()
{
#ifdef __AFL_HAVE_MANUAL_CONTROL
    while (__AFL_LOOP(1000))
    {
#endif
        // copy stdin to byte vector
        std::vector<uint8_t> vec;
        char c;
        while (std::cin.get(c))
        {
            vec.push_back(static_cast<uint8_t>(c));
        }

        LLVMFuzzerTestOneInput(vec.data(), vec.size());
#ifdef __AFL_HAVE_MANUAL_CONTROL
    }
#endif
}
Пример #11
0
int main(int argc, char **argv) {
  fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
  LLVMFuzzerInitialize(&argc, &argv);

  for (int i = 1; i < argc; i++) {
    fprintf(stderr, "Running: %s\n", argv[i]);
    FILE *f = fopen(argv[i], "r");
    assert(f);
    fseek(f, 0, SEEK_END);
    size_t len = ftell(f);
    fseek(f, 0, SEEK_SET);
    unsigned char *buf = (unsigned char*)malloc(len);
    size_t n_read = fread(buf, 1, len, f);
    assert(n_read == len);
    LLVMFuzzerTestOneInput(buf, len);
    free(buf);
    fprintf(stderr, "Done:    %s: (%zd bytes)\n", argv[i], n_read);
  }
}
Пример #12
0
int main(int argc, char **argv)
{
    int i, j;

    for (i = 1; i < argc; i++) {
        char *name = argv[i];
        ssize_t size;
        FILE *f = fopen(name, "rb");
        char *buf;

        fprintf(stdout, "%s...\n", name);
        if (f == NULL) {
            perror("fopen() failed");
            continue;
        }
        fseek(f, 0, SEEK_END);
        size = ftell(f);
        if (size < 0) {
            fclose(f);
            perror("ftell() failed");
            continue;
        }
        fseek(f, 0, SEEK_SET);
        buf = malloc(size + 1);
        if (fread(buf, 1, size, f) != (size_t)size) {
            fclose(f);
            perror("fread() failed");
            continue;
        }
        fclose(f);
        buf[size] = 0;

        for (j = 0; j < MIN_NUMBER_OF_RUNS; j++) {
            if (LLVMFuzzerTestOneInput((void *)buf, size) == EXIT_TEST_SKIP) {
                return EXIT_TEST_SKIP;
            }
        }
        free(buf);
    }

    return EXIT_SUCCESS;
}
Пример #13
0
int main(int argc, char *argv[])
{
	FILE *file = fopen("clusterfuzz-testcase", "r");

	fseek(file, 0L, SEEK_END);
	long numbytes = ftell(file);
	fseek(file, 0L, SEEK_SET);
	uint8_t *buffer = (uint8_t*)calloc(numbytes, sizeof(uint8_t));
	fread(buffer, sizeof(char), numbytes, file);
	fclose(file);

	while(true)
	{
		LLVMFuzzerTestOneInput(buffer, numbytes);
	}

	free(buffer);

	return 0;
}
Пример #14
0
int main(int argc, char** argv)
{
    FILE * fp;
    uint8_t Data[0x1000];
    size_t Size;
    DIR *d;
    struct dirent *dir;
    int r = 0;
    int i;

    if (argc != 2) {
        return 1;
    }

    d = opendir(argv[1]);
    if (d == NULL) {
        printf("Invalid directory\n");
        return 2;
    }
    if (chdir(argv[1]) != 0) {
        closedir(d);
        printf("Invalid directory\n");
        return 2;
    }

    while((dir = readdir(d)) != NULL) {
        //opens the file, get its size, and reads it into a buffer
        if (dir->d_type != DT_REG) {
            continue;
        }
        printf("Running file %s ", dir->d_name);
        fflush(stdout);
        fp = fopen(dir->d_name, "rb");
        if (fp == NULL) {
            r = 3;
            break;
        }
        if (fseek(fp, 0L, SEEK_END) != 0) {
            fclose(fp);
            r = 4;
            break;
        }
        Size = ftell(fp);
        if (Size == (size_t) -1) {
            fclose(fp);
            r = 5;
            break;
        } else if (Size > 0x1000) {
            fclose(fp);
            continue;
        }
        if (fseek(fp, 0L, SEEK_SET) != 0) {
            fclose(fp);
            r = 7;
            break;
        }
        if (fread(Data, Size, 1, fp) != 1) {
            fclose(fp);
            r = 8;
            break;
        }
        if (Size > 0) {
            printf("command cstool %s\n", get_platform_cstoolname(Data[0]));
        }
        for (i=0; i<Size; i++) {
            printf("%02x", Data[i]);
        }
        printf("\n");

        //lauch fuzzer
        LLVMFuzzerTestOneInput(Data, Size);
        fclose(fp);
    }
    closedir(d);
    printf("Ok : whole directory finished\n");
    return r;
}
Пример #15
0
int main(int argc, char **argv)
{
int i;

if (argc < 2)
  {
  printf("** No arguments given\n");
  return 0;
  }

for (i = 1; i < argc; i++)
  {
  size_t filelen;
  size_t readsize;
  unsigned char *buffer;
  FILE *f;

  /* Handle a literal string. Copy to an exact size buffer so that checks for
  overrunning work. */

  if (argv[i][0] == '=')
    {
    readsize = strlen(argv[i]) - 1;
    printf("------ <Literal> ------\n");
    printf("Length = %lu\n", readsize);
    printf("%.*s\n", (int)readsize, argv[i]+1);
    buffer = (unsigned char *)malloc(readsize);
    if (buffer == NULL)
      printf("** Failed to allocate %lu bytes of memory\n", readsize);
    else
      {
      memcpy(buffer, argv[i]+1, readsize);
      LLVMFuzzerTestOneInput(buffer, readsize);
      free(buffer);
      }
    continue;
    }

  /* Handle a string given in a file */

  f = fopen(argv[i], "rb");
  if (f == NULL)
    {
    printf("** Failed to open %s: %s\n", argv[i], strerror(errno));
    continue;
    }

  printf("------ %s ------\n", argv[i]);

  fseek(f, 0, SEEK_END);
  filelen = ftell(f);
  fseek(f, 0, SEEK_SET);

  buffer = (unsigned char *)malloc(filelen);
  if (buffer == NULL)
    {
    printf("** Failed to allocate %lu bytes of memory\n", filelen);
    fclose(f);
    continue;
    }

  readsize = fread(buffer, 1, filelen, f);
  fclose(f);

  if (readsize != filelen)
    printf("** File size is %lu but fread() returned %lu\n", filelen, readsize);
  else
    {
    printf("Length = %lu\n", filelen);
    LLVMFuzzerTestOneInput(buffer, filelen);
    }
  free(buffer);
  }

return 0;
}
Пример #16
0
/*
** Read files named on the command-line and invoke the fuzzer for
** each one.
*/
int main(int argc, char **argv){
  FILE *in;
  int i;
  int nErr = 0;
  uint8_t *zBuf = 0;
  size_t sz;
  unsigned mDebug = 0;

  for(i=1; i<argc; i++){
    const char *zFilename = argv[i];
    if( zFilename[0]=='-' ){
      if( zFilename[1]=='-' ) zFilename++;
      if( strcmp(zFilename, "-show-errors")==0 ){
        mDebug |= FUZZ_SHOW_ERRORS;
        ossfuzz_set_debug_flags(mDebug);
      }else
      if( strcmp(zFilename, "-show-max-delay")==0 ){
        mDebug |= FUZZ_SHOW_MAX_DELAY;
        ossfuzz_set_debug_flags(mDebug);
      }else
      if( strcmp(zFilename, "-sql-trace")==0 ){
        mDebug |= FUZZ_SQL_TRACE;
        ossfuzz_set_debug_flags(mDebug);
      }else
      {
        printf("unknown option \"%s\"\n", argv[i]);
        printf("should be one of: --show-errors --show-max-delay"
               " --sql-trace\n");
        exit(1);
      }
      continue;
    }
    in = fopen(zFilename, "rb");
    if( in==0 ){
      fprintf(stderr, "cannot open \"%s\"\n", zFilename);
      nErr++;
      continue;
    }
    fseek(in, 0, SEEK_END);
    sz = ftell(in);
    rewind(in);
    zBuf = realloc(zBuf, sz);
    if( zBuf==0 ){
      fprintf(stderr, "cannot malloc() for %d bytes\n", (int)sz);
      exit(1);
    }
    if( fread(zBuf, sz, 1, in)!=1 ){
      fprintf(stderr, "cannot read %d bytes from \"%s\"\n",
                       (int)sz, zFilename);
      nErr++;
    }else{
      printf("%s... ", zFilename);
      if( mDebug ) printf("\n");
      fflush(stdout);
      (void)LLVMFuzzerTestOneInput(zBuf, sz);
      if( mDebug ) printf("%s: ", zFilename);
      printf("ok\n");
    }
    fclose(in);
  }
  free(zBuf);
  return nErr;
}