- stat(argv[n], &st);
- f = fopen(argv[n], "rb");
- if (f == NULL)
- continue;
- buf = malloc(st.st_size);
- s = fread(buf, 1, st.st_size, f);
- OPENSSL_assert(s == (size_t)st.st_size);
- FuzzerTestOneInput(buf, s);
- free(buf);
- fclose(f);
+ /*
+ * We start with trying to read the given path as a directory.
+ */
+ while ((filename = OPENSSL_DIR_read(&ctx, argv[n])) != NULL) {
+ wasdir = 1;
+ if (pathname == NULL) {
+ pathname = malloc(PATH_MAX);
+ if (pathname == NULL)
+ break;
+ strcpy(pathname, argv[n]);
+#ifdef __VMS
+ if (strchr(":<]", pathname[dirname_len - 1]) == NULL)
+#endif
+ pathname[dirname_len++] = '/';
+ pathname[dirname_len] = '\0';
+ }
+ strcpy(pathname + dirname_len, filename);
+ testfile(pathname);
+ }
+ OPENSSL_DIR_end(&ctx);
+
+ /* If it wasn't a directory, treat it as a file instead */
+ if (!wasdir)
+ testfile(argv[n]);
+
+ free(pathname);