dhcpd: Check cf_item_parse result
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Tue, 9 Sep 2014 11:29:55 +0000 (14:29 +0300)
committerNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Tue, 9 Sep 2014 15:06:27 +0000 (18:06 +0300)
Check the result of cf_item_parse for error, propagating it up the
stack in dhcp_socket_parse.

Coverity has reported the following errors for this issue.

Error: CHECKED_RETURN (CWE-252):
freeradius-server-3.0.4rc2/src/modules/proto_dhcp/dhcpd.c:638: check_return: Calling function "cf_item_parse(CONF_SECTION *, char const *, int, void *, char const *)" without checking return value (as is done elsewhere 12 out of 14 times).
freeradius-server-3.0.4rc2/src/main/conffile.c:1416: example_assign: Example 1: Assigning: "ret" = return value from "cf_item_parse(cs, (variables + i).name, (variables + i).type, data, (variables + i).dflt)".
freeradius-server-3.0.4rc2/src/main/conffile.c:1417: example_checked: Example 1 (cont.): "ret" has its value checked in "ret < 0".
freeradius-server-3.0.4rc2/src/main/command.c:1569: example_assign: Example 2: Assigning: "rcode" = return value from "cf_item_parse(mi->cs, argv[1], (variables + i).type, data, argv[2])".
freeradius-server-3.0.4rc2/src/main/command.c:1570: example_checked: Example 2 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/main/listen.c:916: example_assign: Example 3: Assigning: "rcode" = return value from "cf_item_parse(cs, "ipaddr", 14, &ipaddr, NULL)".
freeradius-server-3.0.4rc2/src/main/listen.c:917: example_checked: Example 3 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/main/listen.c:2834: example_assign: Example 4: Assigning: "rcode" = return value from "cf_item_parse(cs, "type", 1, &listen_type, "")".
freeradius-server-3.0.4rc2/src/main/listen.c:2835: example_checked: Example 4 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/main/radmin.c:530: example_assign: Example 5: Assigning: "rcode" = return value from "cf_item_parse(subcs, "socket", 1, &file, NULL)".
freeradius-server-3.0.4rc2/src/main/radmin.c:531: example_checked: Example 5 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/modules/proto_dhcp/dhcpd.c:638: unchecked_value: No check of the return value of "cf_item_parse(cs, "suppress_responses", 23, &sock->suppress_responses, NULL)".

Error: CHECKED_RETURN (CWE-252):
freeradius-server-3.0.4rc2/src/modules/proto_dhcp/dhcpd.c:643: check_return: Calling function "cf_item_parse(CONF_SECTION *, char const *, int, void *, char const *)" without checking return value (as is done elsewhere 12 out of 14 times).
freeradius-server-3.0.4rc2/src/main/conffile.c:1416: example_assign: Example 1: Assigning: "ret" = return value from "cf_item_parse(cs, (variables + i).name, (variables + i).type, data, (variables + i).dflt)".
freeradius-server-3.0.4rc2/src/main/conffile.c:1417: example_checked: Example 1 (cont.): "ret" has its value checked in "ret < 0".
freeradius-server-3.0.4rc2/src/main/command.c:1569: example_assign: Example 2: Assigning: "rcode" = return value from "cf_item_parse(mi->cs, argv[1], (variables + i).type, data, argv[2])".
freeradius-server-3.0.4rc2/src/main/command.c:1570: example_checked: Example 2 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/main/listen.c:916: example_assign: Example 3: Assigning: "rcode" = return value from "cf_item_parse(cs, "ipaddr", 14, &ipaddr, NULL)".
freeradius-server-3.0.4rc2/src/main/listen.c:917: example_checked: Example 3 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/main/listen.c:2834: example_assign: Example 4: Assigning: "rcode" = return value from "cf_item_parse(cs, "type", 1, &listen_type, "")".
freeradius-server-3.0.4rc2/src/main/listen.c:2835: example_checked: Example 4 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/main/radmin.c:530: example_assign: Example 5: Assigning: "rcode" = return value from "cf_item_parse(subcs, "socket", 1, &file, NULL)".
freeradius-server-3.0.4rc2/src/main/radmin.c:531: example_checked: Example 5 (cont.): "rcode" has its value checked in "rcode < 0".
freeradius-server-3.0.4rc2/src/modules/proto_dhcp/dhcpd.c:643: unchecked_value: No check of the return value of "cf_item_parse(cs, "src_interface", 1, &sock->src_interface, NULL)".

src/modules/proto_dhcp/dhcpd.c

index 7fca72c..f372487 100644 (file)
@@ -635,12 +635,14 @@ static int dhcp_socket_parse(CONF_SECTION *cs, rad_listen_t *this)
        sock->suppress_responses = false;
        cp = cf_pair_find(cs, "suppress_responses");
        if (cp) {
-               cf_item_parse(cs, "suppress_responses", FR_ITEM_POINTER(PW_TYPE_BOOLEAN, &sock->suppress_responses), NULL);
+               rcode = cf_item_parse(cs, "suppress_responses", FR_ITEM_POINTER(PW_TYPE_BOOLEAN, &sock->suppress_responses), NULL);
+               if (rcode < 0) return -1;
        }
 
        cp = cf_pair_find(cs, "src_interface");
        if (cp) {
-               cf_item_parse(cs, "src_interface", FR_ITEM_POINTER(PW_TYPE_STRING, &sock->src_interface), NULL);
+               rcode = cf_item_parse(cs, "src_interface", FR_ITEM_POINTER(PW_TYPE_STRING, &sock->src_interface), NULL);
+               if (rcode < 0) return -1;
        } else {
                sock->src_interface = sock->lsock.interface;
        }