EAP-SIM DB: Make recv() null termination easier for static analyzers

For some reason, the previous version was not understood to be null
terminating the buffer from recv(). It was doing this fine, though. Try
to use a bit more simpler design in hopes of getting static analyzers to
understand this. (CID 72702)

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-12-06 18:28:00 +02:00
parent 8105821b39
commit 41f480005f

View file

@ -573,16 +573,14 @@ static void eap_sim_db_receive(int sock, void *eloop_ctx, void *sock_ctx)
char buf[1000], *pos, *cmd, *imsi; char buf[1000], *pos, *cmd, *imsi;
int res; int res;
res = recv(sock, buf, sizeof(buf), 0); res = recv(sock, buf, sizeof(buf) - 1, 0);
if (res < 0) if (res < 0)
return; return;
buf[res] = '\0';
wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-SIM DB: Received from an " wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-SIM DB: Received from an "
"external source", (u8 *) buf, res); "external source", (u8 *) buf, res);
if (res == 0) if (res == 0)
return; return;
if (res >= (int) sizeof(buf))
res = sizeof(buf) - 1;
buf[res] = '\0';
if (data->get_complete_cb == NULL) { if (data->get_complete_cb == NULL) {
wpa_printf(MSG_DEBUG, "EAP-SIM DB: No get_complete_cb " wpa_printf(MSG_DEBUG, "EAP-SIM DB: No get_complete_cb "