]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pimd: add fuzzing shunt
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 18 Nov 2019 05:40:41 +0000 (00:40 -0500)
committerQuentin Young <qlyoung@nvidia.com>
Mon, 15 Nov 2021 19:39:32 +0000 (14:39 -0500)
Add ability to read a raw pim packet from stdin and parse it. Useful for
fuzzing pim packet parsing.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
pimd/pim_main.c

index 780595ca11fb979fb3e4344a43c2b79bec883855..778655c11f4cd3df33ec5e0362cb65250d60cc9a 100644 (file)
 #include "pim_errors.h"
 #include "pim_nb.h"
 
+#define FUZZING 1
+#ifdef FUZZING
+#include "pim_pim.h"
+#endif
+
 extern struct host host;
 
 struct option longopts[] = {{0}};
@@ -118,6 +123,26 @@ int main(int argc, char **argv, char **envp)
                }
        }
 
+#ifdef FUZZING
+       pim_router_init();
+       pim_vrf_init();
+       pim_init();
+
+       fseek(stdin, 0, SEEK_END);
+       long fsize = ftell(stdin);
+       fseek(stdin, 0, SEEK_SET);
+       uint8_t *packet = malloc(fsize);
+       fread(packet, 1, fsize, stdin);
+
+       struct interface *ifp = if_create_name("fuzziface", VRF_DEFAULT);
+       pim_if_new(ifp, true, true, false, false);
+       int result = pim_pim_packet(ifp, packet, fsize);
+
+       /* printf is expensive, skip it for fuzzing */
+       //fprintf(stderr, "parse result: %d\n", result);
+       exit(0);
+#endif
+
        pim_router_init();
 
        /*
@@ -133,6 +158,7 @@ int main(int argc, char **argv, char **envp)
        pim_route_map_init();
        pim_init();
 
+
        /*
         * Initialize zclient "update" and "lookup" sockets
         */