| From: Dan Moulding <dmoulding@me.com> |
| Subject: init-add-hostname-kernel-parameter-v2 |
| |
| Link: https://lkml.kernel.org/r/20220506060310.7495-2-dmoulding@me.com |
| Signed-off-by: Dan Moulding <dmoulding@me.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| Documentation/admin-guide/kernel-parameters.txt | 4 ++-- |
| init/version.c | 6 +++--- |
| 2 files changed, 5 insertions(+), 5 deletions(-) |
| |
| --- a/Documentation/admin-guide/kernel-parameters.txt~init-add-hostname-kernel-parameter-v2 |
| +++ a/Documentation/admin-guide/kernel-parameters.txt |
| @@ -1665,6 +1665,8 @@ |
| Valid parameters: "on", "off" |
| Default: "on" |
| |
| + hlt [BUGS=ARM,SH] |
| + |
| hostname= [KNL] Set the hostname (aka UTS nodename). |
| Format: <string> |
| This allows setting the system's hostname during early |
| @@ -1678,8 +1680,6 @@ |
| not exceed the maximum allowed hostname length (usually |
| 64 characters) and will be truncated otherwise. |
| |
| - hlt [BUGS=ARM,SH] |
| - |
| hpet= [X86-32,HPET] option to control HPET usage |
| Format: { enable (default) | disable | force | |
| verbose } |
| --- a/init/version.c~init-add-hostname-kernel-parameter-v2 |
| +++ a/init/version.c |
| @@ -41,12 +41,12 @@ static int __init early_hostname(char *a |
| { |
| size_t bufsize = sizeof(init_uts_ns.name.nodename); |
| size_t maxlen = bufsize - 1; |
| + size_t arglen; |
| |
| - strncpy(init_uts_ns.name.nodename, arg, bufsize); |
| - if (strlen(arg) > maxlen) { |
| + arglen = strlcpy(init_uts_ns.name.nodename, arg, bufsize); |
| + if (arglen > maxlen) { |
| pr_warn("hostname parameter exceeds %zd characters and will be truncated", |
| maxlen); |
| - init_uts_ns.name.nodename[maxlen] = '\0'; |
| } |
| return 0; |
| } |
| _ |