Make dl_list_first() and dl_list_last() uses easier for static analyzers

The previous check for dl_list_len() or having an entry from the list is
sufficient, but some static analyzers cannot figure out that
dl_list_first() and dl_list_last() will return non-NULL in this type of
cases. Avoid invalid reports by explicitly checking for NULL.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-04-26 11:43:25 +03:00
parent 5f693cb1b6
commit 0bceb8d6f4
5 changed files with 23 additions and 16 deletions

View file

@ -1906,7 +1906,7 @@ static void wpa_driver_test_scan_cmd(struct wpa_driver_test_data *drv,
/* data: optional [ STA-addr | ' ' | IEs(hex) ] */ /* data: optional [ STA-addr | ' ' | IEs(hex) ] */
if (!drv->ibss) if (bss == NULL || !drv->ibss)
return; return;
pos = buf; pos = buf;

View file

@ -4210,7 +4210,7 @@ p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next)
dev = dl_list_first(&dev->list, dev = dl_list_first(&dev->list,
struct p2p_device, struct p2p_device,
list); list);
if (&dev->list == &p2p->devices) if (!dev || &dev->list == &p2p->devices)
return NULL; return NULL;
} while (dev->flags & P2P_DEV_PROBE_REQ_ONLY); } while (dev->flags & P2P_DEV_PROBE_REQ_ONLY);
} }
@ -4222,7 +4222,7 @@ p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next)
dev = dl_list_first(&dev->list, dev = dl_list_first(&dev->list,
struct p2p_device, struct p2p_device,
list); list);
if (&dev->list == &p2p->devices) if (!dev || &dev->list == &p2p->devices)
return NULL; return NULL;
} }
} }

View file

@ -134,6 +134,8 @@ next_advertisement(struct upnp_wps_device_sm *sm,
*islast = 0; *islast = 0;
iface = dl_list_first(&sm->interfaces, iface = dl_list_first(&sm->interfaces,
struct upnp_wps_device_interface, list); struct upnp_wps_device_interface, list);
if (!iface)
return NULL;
uuid_bin2str(iface->wps->uuid, uuid_string, sizeof(uuid_string)); uuid_bin2str(iface->wps->uuid, uuid_string, sizeof(uuid_string));
msg = wpabuf_alloc(800); /* more than big enough */ msg = wpabuf_alloc(800); /* more than big enough */
if (msg == NULL) if (msg == NULL)
@ -587,6 +589,8 @@ static void ssdp_parse_msearch(struct upnp_wps_device_sm *sm,
&sm->interfaces, &sm->interfaces,
struct upnp_wps_device_interface, struct upnp_wps_device_interface,
list); list);
if (!iface)
continue;
data += os_strlen("uuid:"); data += os_strlen("uuid:");
uuid_bin2str(iface->wps->uuid, uuid_string, uuid_bin2str(iface->wps->uuid, uuid_string,
sizeof(uuid_string)); sizeof(uuid_string));

View file

@ -179,15 +179,12 @@ static const char *wps_device_xml_postfix =
/* format_wps_device_xml -- produce content of "file" wps_device.xml /* format_wps_device_xml -- produce content of "file" wps_device.xml
* (UPNP_WPS_DEVICE_XML_FILE) * (UPNP_WPS_DEVICE_XML_FILE)
*/ */
static void format_wps_device_xml(struct upnp_wps_device_sm *sm, static void format_wps_device_xml(struct upnp_wps_device_interface *iface,
struct upnp_wps_device_sm *sm,
struct wpabuf *buf) struct wpabuf *buf)
{ {
const char *s; const char *s;
char uuid_string[80]; char uuid_string[80];
struct upnp_wps_device_interface *iface;
iface = dl_list_first(&sm->interfaces,
struct upnp_wps_device_interface, list);
wpabuf_put_str(buf, wps_device_xml_prefix); wpabuf_put_str(buf, wps_device_xml_prefix);
@ -319,6 +316,10 @@ static void web_connection_parse_get(struct upnp_wps_device_sm *sm,
iface = dl_list_first(&sm->interfaces, iface = dl_list_first(&sm->interfaces,
struct upnp_wps_device_interface, list); struct upnp_wps_device_interface, list);
if (iface == NULL) {
http_request_deinit(hreq);
return;
}
/* /*
* It is not required that filenames be case insensitive but it is * It is not required that filenames be case insensitive but it is
@ -391,7 +392,7 @@ static void web_connection_parse_get(struct upnp_wps_device_sm *sm,
switch (req) { switch (req) {
case GET_DEVICE_XML_FILE: case GET_DEVICE_XML_FILE:
format_wps_device_xml(sm, buf); format_wps_device_xml(iface, sm, buf);
break; break;
case GET_SCPD_XML_FILE: case GET_SCPD_XML_FILE:
wpabuf_put_str(buf, wps_scpd_xml); wpabuf_put_str(buf, wps_scpd_xml);
@ -419,13 +420,14 @@ web_process_get_device_info(struct upnp_wps_device_sm *sm,
iface = dl_list_first(&sm->interfaces, iface = dl_list_first(&sm->interfaces,
struct upnp_wps_device_interface, list); struct upnp_wps_device_interface, list);
peer = &iface->peer;
wpa_printf(MSG_DEBUG, "WPS UPnP: GetDeviceInfo"); wpa_printf(MSG_DEBUG, "WPS UPnP: GetDeviceInfo");
if (iface->ctx->ap_pin == NULL) if (!iface || iface->ctx->ap_pin == NULL)
return HTTP_INTERNAL_SERVER_ERROR; return HTTP_INTERNAL_SERVER_ERROR;
peer = &iface->peer;
/* /*
* Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS * Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS
* registration over UPnP with the AP acting as an Enrollee. It should * registration over UPnP with the AP acting as an Enrollee. It should
@ -473,6 +475,8 @@ web_process_put_message(struct upnp_wps_device_sm *sm, char *data,
iface = dl_list_first(&sm->interfaces, iface = dl_list_first(&sm->interfaces,
struct upnp_wps_device_interface, list); struct upnp_wps_device_interface, list);
if (!iface)
return HTTP_INTERNAL_SERVER_ERROR;
/* /*
* PutMessage is used by external UPnP-based Registrar to perform WPS * PutMessage is used by external UPnP-based Registrar to perform WPS

View file

@ -6781,7 +6781,7 @@ void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr,
{ {
struct wpa_ssid *ssid = wpa_s->current_ssid; struct wpa_ssid *ssid = wpa_s->current_ssid;
struct wpa_ssid *persistent; struct wpa_ssid *persistent;
struct psk_list_entry *p; struct psk_list_entry *p, *last;
if (psk_len != sizeof(p->psk)) if (psk_len != sizeof(p->psk))
return; return;
@ -6841,10 +6841,9 @@ void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr,
} }
os_memcpy(p->psk, psk, psk_len); os_memcpy(p->psk, psk, psk_len);
if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS) { if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS &&
struct psk_list_entry *last; (last = dl_list_last(&persistent->psk_list,
last = dl_list_last(&persistent->psk_list, struct psk_list_entry, list))) {
struct psk_list_entry, list);
wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for " wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for "
MACSTR " (p2p=%u) to make room for a new one", MACSTR " (p2p=%u) to make room for a new one",
MAC2STR(last->addr), last->p2p); MAC2STR(last->addr), last->p2p);