You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/12/29 12:03:30 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #5107: Ensure that sethostname null terminates the hostname correctly

xiaoxiang781216 commented on a change in pull request #5107:
URL: https://github.com/apache/incubator-nuttx/pull/5107#discussion_r776292787



##########
File path: libs/libc/unistd/lib_sethostname.c
##########
@@ -116,8 +116,8 @@ int sethostname(FAR const char *name, size_t size)
    */
 
   flags = enter_critical_section();
-  strncpy(g_hostname, name, MIN(HOST_NAME_MAX, size));
-  g_hostname[HOST_NAME_MAX] = '\0';
+  strncpy(g_hostname, name, MIN(HOST_NAME_MAX, namelen));

Review comment:
       should we change to strlcpy?
   https://stackoverflow.com/questions/6987217/strncpy-or-strlcpy-in-my-case
   Actually, I guess many place which call strncpy may suffer the similar issue. So, it will be better to replace all occurrence.
   




-- 
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-unsubscribe@nuttx.apache.org

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