display: use l_strlcpy to avoid potential overflow
PATCH 1/5 display: use l_strlcpy to avoid potential overflow
If 'entry' exceeds the length of 'line' we could overflow. Instead use l_strlcpy and pass in the remaining amount of data left in the buffer.
--- client/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
client/display.c +1 -1
@@ -419,7 +419,7 @@ static void display_completion_matches(char **matches, int num_matches, } entry =l_strdup_printf ("%-*s " , max_length, matches[index]); -strcpy (&line[line_used], entry); +l_strlcpy (&line[line_used], entry,sizeof (line) - line_used);l_free (entry); line_used += max_length +1 ;
Signature · 1 line
2.26.2
PATCH 2/5 client: check mkdir return in display_init
Printing a warning is about all that we can do at this point during initialization.
--- client/display.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
client/display.c +7 -1
@@ -681,6 +681,7 @@ void display_init(void) {const char *data_home;char *data_path; +int ret; display_refresh.redo_entries =l_queue_new ();
@@ -701,7 +702,12 @@ void display_init(void) }if (data_path) { -mkdir (data_path,0700 ); + ret =mkdir (data_path,0700 ); +/* Not much can be done since display isn't even initialized */ +if (L_WARN_ON (ret <0 )) { +l_free (data_path); +return ; + } history_path =l_strdup_printf ("%s/history" , data_path);read_history (history_path);
Signature · 1 line
2.26.2
PATCH 3/5 adhoc: fix missing call to va_end
In reply to James Prestwood--- src/adhoc.c | 2 ++ 1 file changed, 2 insertions(+)
src/adhoc.c +2 -0
@@ -228,6 +228,8 @@ static void adhoc_handshake_event(struct handshake_state *hs,default :break ; } + +va_end (args); } static struct eapol_sm *adhoc_new_sm(struct sta_state *sta, bool authenticator,
Signature · 1 line
2.26.2
Re: [PATCH 3/5] adhoc: fix missing call to va_end
Hi James,
Quoted 9 lines · James Prestwood
--- src/adhoc.c | 2 ++ 1 file changed, 2 insertions(+)src/adhoc.c +0
-0
src/adhoc.c static void adhoc_handshake_event(struct handshake_state *hs, · line 232
Quoted 5 lines
src/adhoc.c +2
-0@@ -228,6 +228,8 @@ static void adhoc_handshake_event(struct handshake_state *hs,default :break ; } + +va_end (args);
I don't think this is correct since there are multiple returns from this function. Perhaps the va_start should be moved to the error cases where it is used.
src/adhoc.c static void adhoc_handshake_event(struct handshake_state *hs, · line 235
Quoted 4 lines
src/adhoc.c +0
-0} static struct eapol_sm *adhoc_new_sm(struct sta_state *sta, bool authenticator,
Regards,
-Denis
PATCH 4/5 ap: free passphrase on error
In reply to James Prestwood--- src/ap.c | 1 + 1 file changed, 1 insertion(+)
src/ap.c +1 -0
@@ -2568,6 +2568,7 @@ static int ap_load_profile_and_dhcp(struct ap_state *ap, bool *wait_dhcp)if (strlen (passphrase) >63 ) {l_error ("[Security].Passphrase must not exceed " "63 characters" ); +l_free (passphrase);return -EINVAL ; }
Signature · 1 line
2.26.2
PATCH 5/5 ap: massage code to make static analysis happy
In reply to James PrestwoodThere is no functional change here but checking the return value makes static analysis much happier. Checking the return and setting the default inside the if clause is also consistent with how IWD does it many other places.
--- src/ap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
src/ap.c +4 -3
@@ -3305,7 +3305,7 @@ static void ap_netdev_watch(struct netdev *netdev,static int ap_init (void ) {const struct l_settings *settings =iwd_get_config (); -bool dhcp_enable = false; +bool dhcp_enable; netdev_watch =netdev_watch_add (ap_netdev_watch,NULL ,NULL );
@@ -3320,8 +3320,9 @@ static int ap_init(void)* DHCP server. If no value is found or it is false do not create a * DHCP server. */ -l_settings_get_bool (settings,"General" ,"EnableNetworkConfiguration" , - &dhcp_enable); +if (!l_settings_get_bool (settings,"General" , +"EnableNetworkConfiguration" , &dhcp_enable)) + dhcp_enable = false;if (dhcp_enable) { L_AUTO_FREE_VAR(char *, ip_prefix);
Signature · 1 line
2.26.2
Hi James,
Quoted 7 lines · James Prestwood
If 'entry' exceeds the length of 'line' we could overflow. Instead use
l_strlcpyand pass in the remaining amount of data left in the buffer.--- client/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Patches 1,2,4,5 applied, thanks.
Regards,
-Denis