hs20-osu-client: Explicit checks for snprintf() result
Get rid of the gcc warnings on potentially truncating the output buffer by explicitly checking that there was enough room to write the full string. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
cd92f7f98a
commit
02047e9c88
1 changed files with 57 additions and 21 deletions
|
@ -2018,6 +2018,7 @@ static struct osu_data * parse_osu_providers(const char *fname, size_t *count)
|
||||||
struct osu_data *osu = NULL, *last = NULL;
|
struct osu_data *osu = NULL, *last = NULL;
|
||||||
size_t osu_count = 0;
|
size_t osu_count = 0;
|
||||||
char *pos, *end;
|
char *pos, *end;
|
||||||
|
int res;
|
||||||
|
|
||||||
f = fopen(fname, "r");
|
f = fopen(fname, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
|
@ -2037,15 +2038,20 @@ static struct osu_data * parse_osu_providers(const char *fname, size_t *count)
|
||||||
osu = last;
|
osu = last;
|
||||||
last = &osu[osu_count++];
|
last = &osu[osu_count++];
|
||||||
memset(last, 0, sizeof(*last));
|
memset(last, 0, sizeof(*last));
|
||||||
snprintf(last->bssid, sizeof(last->bssid), "%s",
|
res = os_snprintf(last->bssid, sizeof(last->bssid),
|
||||||
buf + 13);
|
"%s", buf + 13);
|
||||||
|
if (os_snprintf_error(sizeof(last->bssid), res))
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!last)
|
if (!last)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strncmp(buf, "uri=", 4) == 0) {
|
if (strncmp(buf, "uri=", 4) == 0) {
|
||||||
snprintf(last->url, sizeof(last->url), "%s", buf + 4);
|
res = os_snprintf(last->url, sizeof(last->url),
|
||||||
|
"%s", buf + 4);
|
||||||
|
if (os_snprintf_error(sizeof(last->url), res))
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2055,26 +2061,37 @@ static struct osu_data * parse_osu_providers(const char *fname, size_t *count)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(buf, "osu_ssid=", 9) == 0) {
|
if (strncmp(buf, "osu_ssid=", 9) == 0) {
|
||||||
snprintf(last->osu_ssid, sizeof(last->osu_ssid),
|
res = os_snprintf(last->osu_ssid,
|
||||||
|
sizeof(last->osu_ssid),
|
||||||
"%s", buf + 9);
|
"%s", buf + 9);
|
||||||
|
if (os_snprintf_error(sizeof(last->osu_ssid), res))
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(buf, "osu_ssid2=", 10) == 0) {
|
if (strncmp(buf, "osu_ssid2=", 10) == 0) {
|
||||||
snprintf(last->osu_ssid2, sizeof(last->osu_ssid2),
|
res = os_snprintf(last->osu_ssid2,
|
||||||
|
sizeof(last->osu_ssid2),
|
||||||
"%s", buf + 10);
|
"%s", buf + 10);
|
||||||
|
if (os_snprintf_error(sizeof(last->osu_ssid2), res))
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os_strncmp(buf, "osu_nai=", 8) == 0) {
|
if (os_strncmp(buf, "osu_nai=", 8) == 0) {
|
||||||
os_snprintf(last->osu_nai, sizeof(last->osu_nai),
|
res = os_snprintf(last->osu_nai, sizeof(last->osu_nai),
|
||||||
"%s", buf + 8);
|
"%s", buf + 8);
|
||||||
|
if (os_snprintf_error(sizeof(last->osu_nai), res))
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os_strncmp(buf, "osu_nai2=", 9) == 0) {
|
if (os_strncmp(buf, "osu_nai2=", 9) == 0) {
|
||||||
os_snprintf(last->osu_nai2, sizeof(last->osu_nai2),
|
res = os_snprintf(last->osu_nai2,
|
||||||
|
sizeof(last->osu_nai2),
|
||||||
"%s", buf + 9);
|
"%s", buf + 9);
|
||||||
|
if (os_snprintf_error(sizeof(last->osu_nai2), res))
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2087,8 +2104,14 @@ static struct osu_data * parse_osu_providers(const char *fname, size_t *count)
|
||||||
continue;
|
continue;
|
||||||
*pos++ = '\0';
|
*pos++ = '\0';
|
||||||
txt = &last->friendly_name[last->friendly_name_count++];
|
txt = &last->friendly_name[last->friendly_name_count++];
|
||||||
snprintf(txt->lang, sizeof(txt->lang), "%s", buf + 14);
|
res = os_snprintf(txt->lang, sizeof(txt->lang),
|
||||||
snprintf(txt->text, sizeof(txt->text), "%s", pos);
|
"%s", buf + 14);
|
||||||
|
if (os_snprintf_error(sizeof(txt->lang), res))
|
||||||
|
break;
|
||||||
|
res = os_snprintf(txt->text, sizeof(txt->text),
|
||||||
|
"%s", pos);
|
||||||
|
if (os_snprintf_error(sizeof(txt->text), res))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(buf, "desc=", 5) == 0) {
|
if (strncmp(buf, "desc=", 5) == 0) {
|
||||||
|
@ -2100,8 +2123,14 @@ static struct osu_data * parse_osu_providers(const char *fname, size_t *count)
|
||||||
continue;
|
continue;
|
||||||
*pos++ = '\0';
|
*pos++ = '\0';
|
||||||
txt = &last->serv_desc[last->serv_desc_count++];
|
txt = &last->serv_desc[last->serv_desc_count++];
|
||||||
snprintf(txt->lang, sizeof(txt->lang), "%s", buf + 5);
|
res = os_snprintf(txt->lang, sizeof(txt->lang),
|
||||||
snprintf(txt->text, sizeof(txt->text), "%s", pos);
|
"%s", buf + 5);
|
||||||
|
if (os_snprintf_error(sizeof(txt->lang), res))
|
||||||
|
break;
|
||||||
|
res = os_snprintf(txt->text, sizeof(txt->text),
|
||||||
|
"%s", pos);
|
||||||
|
if (os_snprintf_error(sizeof(txt->text), res))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(buf, "icon=", 5) == 0) {
|
if (strncmp(buf, "icon=", 5) == 0) {
|
||||||
|
@ -2124,23 +2153,30 @@ static struct osu_data * parse_osu_providers(const char *fname, size_t *count)
|
||||||
if (!end)
|
if (!end)
|
||||||
continue;
|
continue;
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
snprintf(icon->lang, sizeof(icon->lang), "%s", pos);
|
res = os_snprintf(icon->lang, sizeof(icon->lang),
|
||||||
|
"%s", pos);
|
||||||
|
if (os_snprintf_error(sizeof(icon->lang), res))
|
||||||
|
break;
|
||||||
pos = end + 1;
|
pos = end + 1;
|
||||||
|
|
||||||
end = strchr(pos, ':');
|
end = strchr(pos, ':');
|
||||||
if (end)
|
if (end)
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
snprintf(icon->mime_type, sizeof(icon->mime_type),
|
res = os_snprintf(icon->mime_type,
|
||||||
"%s", pos);
|
sizeof(icon->mime_type), "%s", pos);
|
||||||
if (!pos)
|
if (os_snprintf_error(sizeof(icon->mime_type), res))
|
||||||
|
break;
|
||||||
|
if (!end)
|
||||||
continue;
|
continue;
|
||||||
pos = end + 1;
|
pos = end + 1;
|
||||||
|
|
||||||
end = strchr(pos, ':');
|
end = strchr(pos, ':');
|
||||||
if (end)
|
if (end)
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
snprintf(icon->filename, sizeof(icon->filename),
|
res = os_snprintf(icon->filename,
|
||||||
"%s", pos);
|
sizeof(icon->filename), "%s", pos);
|
||||||
|
if (os_snprintf_error(sizeof(icon->filename), res))
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue