csanchezdll commented on code in PR #3059:
URL: https://github.com/apache/nuttx-apps/pull/3059#discussion_r2055591720


##########
canutils/slcan/slcan.c:
##########
@@ -137,8 +137,7 @@ static int caninit(char *candev, int *s, struct 
sockaddr_can *addr,
       syslog(LOG_ERR, "Error opening CAN socket\n");
       return -1;
     }
-  strncpy(ifr.ifr_name, candev, 4);
-  ifr.ifr_name[4] = '\0';
+  strlcpy(ifr.ifr_name, candev, IFNAMSIZ);

Review Comment:
   Agreed `strscpy` is the way to go. However, it is IMHO out of scope if this 
PR, which is required to keep slcan working after recent Nuttx changes. Options:
   1) Leave the code totally untouched with the 4 limit length.
   2) Leave `srtncpy` + explicit `\0` as it was originally (just change the max 
length) [this was my original patch]
   3) Use `strlcpy` [suggested by @xiaoxiang781216]
   4) Port `strscpy` as part of this PR
   5) Block this PR until `strscpy` is ported in another PR
   
   I'd vote for 3. Otherwise 1 and 2 are fine. I think 4 and 5 are bad ideas.



##########
canutils/slcan/slcan.c:
##########
@@ -395,9 +407,22 @@ int main(int argc, char *argv[])
                         {
                           /* close interface */
 
-                          mode = 0;
-                          debug_print("Close interface\n");
-                          ok_return(fd);
+                          struct ifreq ifr;
+
+                          strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ);
+
+                          ifr.ifr_flags = IFF_DOWN;

Review Comment:
   `IFF_DOWN` was removed in https://github.com/apache/nuttx/pull/13842 so 
build checks failed. Fixing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to