File tree Expand file tree Collapse file tree
board/common/rootfs/usr/libexec/infix Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313import json
1414import subprocess
1515import re
16+ def decode_iw_ssid (ssid ):
17+ """Decode iw escaped SSID (\\ xHH) to UTF-8, stripping non-printable chars."""
18+ try :
19+ ssid = ssid .encode ().decode ('unicode_escape' ).encode ('latin-1' ).decode ('utf-8' )
20+ except (UnicodeDecodeError , UnicodeEncodeError ):
21+ return ssid
22+ return '' .join (c for c in ssid if c .isprintable ())
1623
1724
1825def run_iw (* args ):
@@ -260,7 +267,7 @@ def parse_interface_info(ifname):
260267
261268 # SSID
262269 elif stripped .startswith ('ssid ' ):
263- result ['ssid' ] = ' ' .join (stripped .split ()[1 :])
270+ result ['ssid' ] = decode_iw_ssid ( ' ' .join (stripped .split ()[1 :]) )
264271
265272 # Channel/frequency
266273 elif stripped .startswith ('channel ' ):
@@ -488,7 +495,7 @@ def parse_link(ifname):
488495
489496 # SSID: NetworkName
490497 elif stripped .startswith ('SSID: ' ):
491- result ['ssid' ] = stripped [6 :]
498+ result ['ssid' ] = decode_iw_ssid ( stripped [6 :])
492499
493500 # freq: 5180
494501 elif stripped .startswith ('freq: ' ):
@@ -582,7 +589,7 @@ def main():
582589 else :
583590 data = {'error' : f'Unknown command: { command } ' }
584591
585- print (json .dumps (data , indent = 2 ))
592+ print (json .dumps (data , indent = 2 , ensure_ascii = False ))
586593
587594 except Exception as e :
588595 print (json .dumps ({'error' : str (e )}))
Original file line number Diff line number Diff line change @@ -151,6 +151,9 @@ submodule infix-if-wifi {
151151 leaf ssid {
152152 type string {
153153 length "1..32" ;
154+ pattern '[^\x00-\x1f\x22\x5c\x7f]*' {
155+ error-message "SSID must not contain control characters, double quotes, or backslashes." ;
156+ }
154157 }
155158 mandatory true ;
156159 description
@@ -322,6 +325,9 @@ submodule infix-if-wifi {
322325 leaf ssid {
323326 type string {
324327 length "1..32" ;
328+ pattern '[^\x00-\x1f\x22\x5c\x7f]*' {
329+ error-message "SSID must not contain control characters, double quotes, or backslashes." ;
330+ }
325331 }
326332 mandatory true ;
327333 description
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ def dirpath(path):
9797 common .LOG .warning ("Unsupported model %s" , args .model )
9898 sys .exit (1 )
9999
100- print (json .dumps (yang_data , indent = 2 ))
100+ print (json .dumps (yang_data , indent = 2 , ensure_ascii = False ))
101101
102102
103103if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -122,9 +122,15 @@ def parse_wpa_scan_result(scan_output):
122122
123123 flags = parts [3 ].strip ()
124124 ssid = parts [4 ].strip () if len (parts ) > 4 else ""
125+ try :
126+ ssid = ssid .encode ().decode ('unicode_escape' ).encode ('latin-1' ).decode ('utf-8' )
127+ except (UnicodeDecodeError , UnicodeEncodeError ):
128+ pass
129+ # Strip control chars (terminal injection risk from rogue APs)
130+ ssid = '' .join (c for c in ssid if c .isprintable ())
125131
126132 # Skip hidden SSIDs (empty or null-filled)
127- if not ssid or ssid .isspace () or ' \\ x00' in ssid :
133+ if not ssid or ssid .isspace ():
128134 continue
129135
130136 encryption = extract_encryption (flags )
You can’t perform that action at this time.
0 commit comments