💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › a4de822d171d0917b4a568f948af1… captured on 2023-12-28 at 15:42:53. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Go Back

0 /*

1 * ISC License

2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>

3 */

4 #ifdef DEBUG

5 #include <stdio.h>

6 #include <stdlib.h>

7 #include <unistd.h>

8 #include <fcntl.h>

9 #include <string.h>

10 #include "macro.h"

11 #include "page.h"

12 #include "request.h"

13 #include "parser.h"

14

15 int parse_file(const char *path) {

16

17 size_t length;

18 int in, out, i;

19

20 in = open(path, O_RDONLY);

21 if (in < 0) return -1;

22 length = lseek(in, 0, SEEK_END);

23 close(in);

24

25 out = open("/dev/null", O_WRONLY);

26 if (out < 0) return -1;

27

28 /* test range of different width */

29 for (i = 0; i < 1024; i++) {

30 in = open(path, O_RDONLY);

31 if (in < 0) {

32 close(out);

33 return -1;

34 }

35 parse_gemtext(in, length, i, out);

36 close(in);

37 }

38

39 close(out);

40 return 0;

41 }

42

43 /* warning: doesn't detect deadlock */

44 int fuzzing(int iterations) {

45

46 int i;

47 int fd, randfd;

48

49 fd = open("/dev/null", O_WRONLY);

50 if (fd < 0) return -1;

51

52 randfd = open("/dev/random", O_RDONLY);

53 if (randfd < 0) return -1;

54

55 for (i = 0; i < iterations; i++) {

56 int width;

57 size_t length, j;

58 read(randfd, P(j));

59 width = j % 40 + 5;

60 read(randfd, P(j));

61 length = j % 10000;

62 parse_gemtext(randfd, length, width, fd);

63 parse_binary(randfd, length, width, fd);

64 parse_plain(randfd, length, width, fd);

65 if (i % 100 == 0) {

66 printf("%d/%d (%d%%)\n", i, iterations,

67 i * 100 / iterations);

68 }

69 }

70 return 0;

71 }

72 #else

73 typedef int hide_warning;

74 #endif

75