mdns: check return value of inet_pton
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 10:27:10 +0000 (12:27 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 11:45:14 +0000 (13:45 +0200)
Coverity:
CID 739616 (#1 of 2): Unchecked return value (CHECKED_RETURN)
At (8): Calling function "inet_pton(int, char const * restrict,
                                    void * restrict)" without checking
        return value (as is done elsewhere 23 out of 25 times).
At (9): No check of the return value of "inet_pton(2, "224.0.0.2",
        &mc_settings.imr_multiaddr.s_addr)".

CID 739616 (#2 of 2): Unchecked return value (CHECKED_RETURN)
At (7): Calling function "inet_pton(int, char const * restrict,
                                    void * restrict)" without checking
        return value (as is done elsewhere 23 out of 25 times).
At (8): No check of the return value of "inet_pton(10, "ff02::2",
        &mc6_settings.ipv6mr_multiaddr.__in6_u.__u6_addr8)".

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/mdns/src/NetworkInterfaces.c

index d6ac280..44cd522 100644 (file)
@@ -271,9 +271,13 @@ CreateRouterElectionSocket(const char *ifName)
         * ADD_MEMBERSHIP option must be called for each local interface over
         * which the multicast datagrams are to be received. */
        if (ipFamilySetting == AF_INET) {
+               static const char * mc4Addr = "224.0.0.2";
                struct ip_mreq mc_settings;
                (void) memset(&mc_settings, 0, sizeof(mc_settings));
-               inet_pton(AF_INET, "224.0.0.2", &mc_settings.imr_multiaddr.s_addr);
+               if (inet_pton(AF_INET, mc4Addr, &mc_settings.imr_multiaddr.s_addr) != 1) {
+                       BmfPError("Could not convert ipv4 multicast address %s", mc4Addr);
+                       goto bail;
+               }
                (void) memset(&req, 0, sizeof(struct ifreq));
                strncpy(req.ifr_name, ifName, IFNAMSIZ - 1);
                req.ifr_name[IFNAMSIZ -1] = '\0';       /* Ensure null termination */
@@ -291,9 +295,13 @@ CreateRouterElectionSocket(const char *ifName)
                        goto bail;
                }
        } else {
+               static const char * mc6Addr = "ff02::2";
                struct ipv6_mreq mc6_settings;
                (void) memset(&mc6_settings, 0, sizeof(mc6_settings));
-               inet_pton(AF_INET6, "ff02::2", &mc6_settings.ipv6mr_multiaddr.s6_addr);
+               if (inet_pton(AF_INET6, mc6Addr, &mc6_settings.ipv6mr_multiaddr.s6_addr) != 1) {
+                       BmfPError("Could not convert ipv6 multicast address %s", mc6Addr);
+                       goto bail;
+               }
                mc6_settings.ipv6mr_interface = ifIndex;
                errno = 0;
                if (setsockopt(rxSocket, ipProtoSetting, ipAddMembershipSetting,