LCOV - code coverage report
Current view: top level - fuzz - fuzz-dhcp6-client.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 0 29 0.0 %
Date: 2019-08-23 13:36:53 Functions: 0 4 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 26 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <unistd.h>
       4                 :            : 
       5                 :            : #include "sd-dhcp6-client.h"
       6                 :            : #include "sd-event.h"
       7                 :            : 
       8                 :            : #include "dhcp6-internal.h"
       9                 :            : #include "dhcp6-protocol.h"
      10                 :            : #include "fd-util.h"
      11                 :            : #include "fuzz.h"
      12                 :            : 
      13                 :            : static int test_dhcp_fd[2] = { -1, -1 };
      14                 :            : 
      15                 :          0 : int dhcp6_network_send_udp_socket(int s, struct in6_addr *server_address,
      16                 :            :                                   const void *packet, size_t len) {
      17                 :          0 :         return len;
      18                 :            : }
      19                 :            : 
      20                 :          0 : int dhcp6_network_bind_udp_socket(int index, struct in6_addr *local_address) {
      21         [ #  # ]:          0 :         assert_se(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_dhcp_fd) >= 0);
      22                 :          0 :         return test_dhcp_fd[0];
      23                 :            : }
      24                 :            : 
      25                 :          0 : static void fuzz_client(const uint8_t *data, size_t size, bool is_information_request_enabled) {
      26                 :          0 :         _cleanup_(sd_event_unrefp) sd_event *e;
      27                 :          0 :         _cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL;
      28                 :          0 :         struct in6_addr address = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01 } } };
      29                 :            : 
      30         [ #  # ]:          0 :         assert_se(sd_event_new(&e) >= 0);
      31         [ #  # ]:          0 :         assert_se(sd_dhcp6_client_new(&client) >= 0);
      32         [ #  # ]:          0 :         assert_se(sd_dhcp6_client_attach_event(client, e, 0) >= 0);
      33         [ #  # ]:          0 :         assert_se(sd_dhcp6_client_set_ifindex(client, 42) == 0);
      34         [ #  # ]:          0 :         assert_se(sd_dhcp6_client_set_local_address(client, &address) >= 0);
      35         [ #  # ]:          0 :         assert_se(sd_dhcp6_client_set_information_request(client, is_information_request_enabled) == 0);
      36                 :            : 
      37         [ #  # ]:          0 :         assert_se(sd_dhcp6_client_start(client) >= 0);
      38                 :            : 
      39         [ #  # ]:          0 :         if (size >= sizeof(DHCP6Message))
      40         [ #  # ]:          0 :                 assert_se(sd_dhcp6_client_set_transaction_id(client, htobe32(0x00ffffff) & ((const DHCP6Message *) data)->transaction_id) == 0);
      41                 :            : 
      42         [ #  # ]:          0 :         assert_se(write(test_dhcp_fd[1], data, size) == (ssize_t) size);
      43                 :            : 
      44                 :          0 :         sd_event_run(e, (uint64_t) -1);
      45                 :            : 
      46         [ #  # ]:          0 :         assert_se(sd_dhcp6_client_stop(client) >= 0);
      47                 :            : 
      48                 :          0 :         test_dhcp_fd[1] = safe_close(test_dhcp_fd[1]);
      49                 :          0 : }
      50                 :            : 
      51                 :          0 : int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
      52         [ #  # ]:          0 :         if (size > 65536)
      53                 :          0 :                 return 0;
      54                 :            : 
      55                 :            :         /* This triggers client_receive_advertise */
      56                 :          0 :         fuzz_client(data, size, false);
      57                 :            : 
      58                 :            :         /* This triggers client_receive_reply */
      59                 :          0 :         fuzz_client(data, size, true);
      60                 :            : 
      61                 :          0 :         return 0;
      62                 :            : }

Generated by: LCOV version 1.14