mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
confd: guard NULL band/ssid/class in WiFi config generation
lydx_get_cattr() yields NULL for an absent leaf or a failed radio component lookup; that NULL was passed straight to strcmp() on several WiFi paths (wifi_chan_to_freq, the wifi_gen_mesh width branches, wifi_find_higher_band_twin, dep_radio_components), risking a crash. Guard each value before use. Fixes Coverity CID 561387, 561389, 561390, 561391, 561392. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -439,7 +439,7 @@ static confd_dependency_t dep_radio_components(struct lyd_node **diff, struct ly
|
||||
class = lyd_get_value(class_node);
|
||||
}
|
||||
|
||||
if (strcmp(class, "infix-hardware:wifi"))
|
||||
if (!class || strcmp(class, "infix-hardware:wifi"))
|
||||
continue;
|
||||
|
||||
/* Find all interfaces that reference this radio */
|
||||
|
||||
@@ -237,7 +237,7 @@ static const char *wifi_find_higher_band_twin(struct lyd_node *config,
|
||||
{
|
||||
struct lyd_node *cifs, *cif;
|
||||
|
||||
if (strcmp(current_band, "2.4GHz"))
|
||||
if (!current_band || !current_ssid || strcmp(current_band, "2.4GHz"))
|
||||
return NULL;
|
||||
|
||||
cifs = lydx_get_descendant(config, "interfaces", "interface", NULL);
|
||||
@@ -252,13 +252,13 @@ static const char *wifi_find_higher_band_twin(struct lyd_node *config,
|
||||
if (!ap)
|
||||
continue;
|
||||
ssid = lydx_get_cattr(ap, "ssid");
|
||||
if (strcmp(ssid, current_ssid))
|
||||
if (!ssid || strcmp(ssid, current_ssid))
|
||||
continue;
|
||||
radio = lydx_get_cattr(wifi, "radio");
|
||||
radio_node = lydx_get_xpathf(config,
|
||||
"/hardware/component[name='%s']/wifi-radio", radio);
|
||||
band = lydx_get_cattr(radio_node, "band");
|
||||
if (!strcmp(band, "5GHz") || !strcmp(band, "6GHz"))
|
||||
if (band && (!strcmp(band, "5GHz") || !strcmp(band, "6GHz")))
|
||||
return lydx_get_cattr(cif, "name");
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ static int wifi_center_chan_160(int ch)
|
||||
*/
|
||||
static int wifi_chan_to_freq(int channel, const char *band)
|
||||
{
|
||||
if (!strcmp(band, "6GHz"))
|
||||
if (band && !strcmp(band, "6GHz"))
|
||||
return 5950 + channel * 5;
|
||||
|
||||
if (channel >= 1 && channel <= 13)
|
||||
@@ -392,7 +392,7 @@ int wifi_gen_mesh(struct lyd_node *cif)
|
||||
int center = wifi_center_chan_80(channel);
|
||||
|
||||
fprintf(wpa_supplicant, " ht40=1\n");
|
||||
if (!strcmp(band, "6GHz"))
|
||||
if (band && !strcmp(band, "6GHz"))
|
||||
fprintf(wpa_supplicant, " he=1\n");
|
||||
else
|
||||
fprintf(wpa_supplicant, " vht=1\n");
|
||||
@@ -403,7 +403,7 @@ int wifi_gen_mesh(struct lyd_node *cif)
|
||||
int center = wifi_center_chan_160(channel);
|
||||
|
||||
fprintf(wpa_supplicant, " ht40=1\n");
|
||||
if (!strcmp(band, "6GHz"))
|
||||
if (band && !strcmp(band, "6GHz"))
|
||||
fprintf(wpa_supplicant, " he=1\n");
|
||||
else
|
||||
fprintf(wpa_supplicant, " vht=1\n");
|
||||
|
||||
Reference in New Issue
Block a user