@@ -310,7 +310,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom
310310 $ status ->addMessage ('Unknown interface ' .htmlspecialchars ($ _POST ['interface ' ], ENT_QUOTES ), 'danger ' );
311311 $ good_input = false ;
312312 }
313- if (strlen ($ _POST ['country_code ' ]) !== 0 && strlen ( $ _POST ['country_code ' ]) != 2 ) {
313+ if (strlen ($ _POST ['country_code ' ]) !== 0 && ! preg_match ( ' /^[A-Z]{2}$/ ' , $ _POST ['country_code ' ])) {
314314 $ status ->addMessage ('Country code must be blank or two characters ' , 'danger ' );
315315 $ good_input = false ;
316316 } else {
@@ -330,6 +330,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom
330330 $ _POST ['max_num_sta ' ] = $ _POST ['max_num_sta ' ] < 1 ? null : $ _POST ['max_num_sta ' ];
331331
332332 if ($ good_input ) {
333+ $ interface = escapeshellarg ($ _POST ['interface ' ]);
333334 $ return = updateHostapdConfig ($ ignore_broadcast_ssid ,$ wifiAPEnable ,$ bridgedEnable );
334335
335336 if (trim ($ country_code ) != trim ($ reg_domain )) {
@@ -357,7 +358,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom
357358 scanConfigDir ('/etc/dnsmasq.d/ ' ,'uap0 ' ,$ status );
358359 $ config = join (PHP_EOL , $ config );
359360 file_put_contents ("/tmp/dnsmasqdata " , $ config );
360- system ('sudo cp /tmp/dnsmasqdata ' .RASPI_DNSMASQ_PREFIX .$ ap_iface .'.conf ' , $ return );
361+ $ destination = RASPI_DNSMASQ_PREFIX . escapeshellarg ($ ap_iface . '.conf ' );
362+ $ command = sprintf ('sudo cp /tmp/dnsmasqdata %s ' , $ destination );
363+ system ($ command , $ return );
361364 } elseif ($ bridgedEnable !==1 ) {
362365 $ dhcp_range = ($ syscfg ['dhcp-range ' ] =='' ) ? getDefaultNetValue ('dnsmasq ' ,$ ap_iface ,'dhcp-range ' ) : $ syscfg ['dhcp-range ' ];
363366 $ config = [ '# RaspAP ' .$ _POST ['interface ' ].' configuration ' ];
@@ -370,7 +373,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom
370373 $ config [] = PHP_EOL ;
371374 $ config = join (PHP_EOL , $ config );
372375 file_put_contents ("/tmp/dnsmasqdata " , $ config );
373- system ('sudo cp /tmp/dnsmasqdata ' .RASPI_DNSMASQ_PREFIX .$ ap_iface .'.conf ' , $ return );
376+ $ destination = RASPI_DNSMASQ_PREFIX . escapeshellarg ($ ap_iface . '.conf ' );
377+ $ command = sprintf ('sudo cp /tmp/dnsmasqdata %s ' , $ destination );
378+ system ($ command , $ return );
374379 }
375380
376381 // Set dhcp values from system config, fallback to default if undefined
@@ -524,7 +529,9 @@ function updateHostapdConfig($ignore_broadcast_ssid,$wifiAPEnable,$bridgedEnable
524529 $ config .= parseUserHostapdCfg ();
525530
526531 file_put_contents ("/tmp/hostapddata " , $ config );
527- system ("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG , $ result );
532+ $ destination = escapeshellarg (RASPI_HOSTAPD_CONFIG );
533+ $ command = sprintf ("sudo cp /tmp/hostapddata %s " , $ destination );
534+ system ($ command , $ result );
528535 return $ result ;
529536}
530537
0 commit comments