Ensure that sethostname null terminates the hostname correctly
commit e1c306f2dd added sethostname using
strncpy. This replaces it with strlcpy and uses sizeof() instead of
re-calculating the buffer size.
Rename size argument for get/sethostname to match the implementation
This commit is contained in:
parent
fc41bb7f8a
commit
df956b08f2
2 changed files with 4 additions and 5 deletions
|
|
@ -386,8 +386,8 @@ FAR int *getopterrp(void); /* Print error message */
|
|||
FAR int *getoptindp(void); /* Index into argv */
|
||||
FAR int *getoptoptp(void); /* Unrecognized option character */
|
||||
|
||||
int gethostname(FAR char *name, size_t size);
|
||||
int sethostname(FAR const char *name, size_t size);
|
||||
int gethostname(FAR char *name, size_t namelen);
|
||||
int sethostname(FAR const char *name, size_t namelen);
|
||||
|
||||
/* Get configurable system variables */
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ extern char g_hostname[HOST_NAME_MAX + 1];
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sethostname(FAR const char *name, size_t size)
|
||||
int sethostname(FAR const char *name, size_t namelen)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
|
|
@ -116,8 +116,7 @@ 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';
|
||||
strlcpy(g_hostname, name, sizeof(g_hostname));
|
||||
leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue