All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] gethostname02: Accept EOVERFLOW on alpha
@ 2026-06-02  9:02 panzhe
  2026-06-02 11:26 ` [LTP] " linuxtestproject.agent
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: panzhe @ 2026-06-02  9:02 UTC (permalink / raw)
  To: ltp

On alpha glibc's gethostname() directly calls the kernel
syscall and sets errno to EOVERFLOW when the buffer is
too small, because the kernel truncates silently and the
string is not null terminated.

On the other hand, the generic posix implementation used
on x86_64 sets ENAMETOOLONG in this case.

Fix this by accepting both errnos.

Closes: https://github.com/linux-test-project/ltp/issues/1319
Signed-off-by: panzhe <panzhe@kylinos.cn>
---
 testcases/kernel/syscalls/gethostname/gethostname02.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/gethostname/gethostname02.c b/testcases/kernel/syscalls/gethostname/gethostname02.c
index c56fcb800..dd1f4e39e 100644
--- a/testcases/kernel/syscalls/gethostname/gethostname02.c
+++ b/testcases/kernel/syscalls/gethostname/gethostname02.c
@@ -7,7 +7,7 @@
 /*\
  * Verify that gethostname(2) fails with
  *
- * - ENAMETOOLONG when len is smaller than the actual size
+ * - ENAMETOOLONG or EOVERFLOW when len is smaller than the actual size
  */
 
 #include "tst_test.h"
@@ -16,11 +16,13 @@ static void verify_gethostname(void)
 {
 	char hostname[HOST_NAME_MAX + 1];
 	int real_length;
+	const int exp_errnos[] = {ENAMETOOLONG, EOVERFLOW};
 
 	SAFE_GETHOSTNAME(hostname, sizeof(hostname));
 	real_length = strlen(hostname);
 
-	TST_EXP_FAIL(gethostname(hostname, real_length - 1), ENAMETOOLONG,
+	TST_EXP_FAIL_ARR(gethostname(hostname, real_length - 1),
+		exp_errnos, ARRAY_SIZE(exp_errnos),
 		"len is smaller than the actual size");
 }
 
-- 
2.25.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] gethostname02: Accept EOVERFLOW on alpha
  2026-06-02  9:02 [LTP] [PATCH v2] gethostname02: Accept EOVERFLOW on alpha panzhe
@ 2026-06-02 11:26 ` linuxtestproject.agent
  2026-06-02 15:57 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp
  2026-06-02 17:34 ` Avinesh Kumar via ltp
  2 siblings, 0 replies; 4+ messages in thread
From: linuxtestproject.agent @ 2026-06-02 11:26 UTC (permalink / raw)
  To: panzhe; +Cc: LTP AI Reviewer, ltp

Hi panzhe,

On Tue, 2026-06-02 at 17:02 +0800, panzhe wrote:
> gethostname02: Accept EOVERFLOW on alpha
>
> On alpha glibc's gethostname() directly calls the kernel
> syscall and sets errno to EOVERFLOW when the buffer is
> too small, because the kernel truncates silently and the
> string is not null terminated.
>
> On the other hand, the generic posix implementation used
> on x86_64 sets ENAMETOOLONG in this case.
>
> Fix this by accepting both errnos.
>
> Closes: https://github.com/linux-test-project/ltp/issues/1319
> Signed-off-by: panzhe <panzhe@kylinos.cn>

Commit message: OK.  The alpha-specific behaviour is confirmed by glibc's
sysdeps/unix/sysv/linux/alpha/gethostname.c:

    result = INLINE_SYSCALL(gethostname, 2, name, len);
    if (result == 0 && memchr(name, '\0', len) == NULL) {
        __set_errno(EOVERFLOW);
        result = -1;
    }

When the kernel truncates the hostname to exactly `len` bytes (no null
terminator), glibc detects the missing '\0' and raises EOVERFLOW.  The
commit message accurately describes this.

> -	TST_EXP_FAIL(gethostname(hostname, real_length - 1), ENAMETOOLONG,
> +	const int exp_errnos[] = {ENAMETOOLONG, EOVERFLOW};
> +	TST_EXP_FAIL_ARR(gethostname(hostname, real_length - 1),
> +		exp_errnos, ARRAY_SIZE(exp_errnos),
> +		"len is smaller than the actual size");

TST_EXP_FAIL_ARR usage is correct.  The array is passed as const int *,
matching the tst_errno_in_set() signature.  ARRAY_SIZE is preferred over a
hardcoded count.  EOVERFLOW is available via <errno.h>, which tst_test.h
already includes.

Note: ltp-linter was not available in the review environment and could not
be run.

Verdict: Reviewed

Reviewed-by: LTP AI Reviewer <ltp-ai-reviewer@lists.linux.it>

LTP AI Reviewer

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] gethostname02: Accept EOVERFLOW on alpha
  2026-06-02  9:02 [LTP] [PATCH v2] gethostname02: Accept EOVERFLOW on alpha panzhe
  2026-06-02 11:26 ` [LTP] " linuxtestproject.agent
@ 2026-06-02 15:57 ` Andrea Cervesato via ltp
  2026-06-02 17:34 ` Avinesh Kumar via ltp
  2 siblings, 0 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2026-06-02 15:57 UTC (permalink / raw)
  To: panzhe; +Cc: ltp

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] gethostname02: Accept EOVERFLOW on alpha
  2026-06-02  9:02 [LTP] [PATCH v2] gethostname02: Accept EOVERFLOW on alpha panzhe
  2026-06-02 11:26 ` [LTP] " linuxtestproject.agent
  2026-06-02 15:57 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp
@ 2026-06-02 17:34 ` Avinesh Kumar via ltp
  2 siblings, 0 replies; 4+ messages in thread
From: Avinesh Kumar via ltp @ 2026-06-02 17:34 UTC (permalink / raw)
  To: panzhe, Linux Test Project

Hi,

On 6/2/26 11:02 AM, panzhe wrote:
> On alpha glibc's gethostname() directly calls the kernel
> syscall and sets errno to EOVERFLOW when the buffer is
> too small, because the kernel truncates silently and the
> string is not null terminated.
> 
> On the other hand, the generic posix implementation used
> on x86_64 sets ENAMETOOLONG in this case.
> 
> Fix this by accepting both errnos.
> 
> Closes: https://github.com/linux-test-project/ltp/issues/1319
> Signed-off-by: panzhe <panzhe@kylinos.cn>
> ---
>   testcases/kernel/syscalls/gethostname/gethostname02.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/gethostname/gethostname02.c b/testcases/kernel/syscalls/gethostname/gethostname02.c
> index c56fcb800..dd1f4e39e 100644
> --- a/testcases/kernel/syscalls/gethostname/gethostname02.c
> +++ b/testcases/kernel/syscalls/gethostname/gethostname02.c
> @@ -7,7 +7,7 @@
>   /*\
>    * Verify that gethostname(2) fails with
>    *
> - * - ENAMETOOLONG when len is smaller than the actual size
> + * - ENAMETOOLONG or EOVERFLOW when len is smaller than the actual size
>    */
>   
>   #include "tst_test.h"
> @@ -16,11 +16,13 @@ static void verify_gethostname(void)
>   {
>   	char hostname[HOST_NAME_MAX + 1];
>   	int real_length;
> +	const int exp_errnos[] = {ENAMETOOLONG, EOVERFLOW};
>   
>   	SAFE_GETHOSTNAME(hostname, sizeof(hostname));
>   	real_length = strlen(hostname);
>   
> -	TST_EXP_FAIL(gethostname(hostname, real_length - 1), ENAMETOOLONG,
> +	TST_EXP_FAIL_ARR(gethostname(hostname, real_length - 1),
> +		exp_errnos, ARRAY_SIZE(exp_errnos),

Please also fix make check error here

 > make check-gethostname02
CHECK testcases/kernel/syscalls/gethostname/gethostname02.c
gethostname02.c:25: CHECK: Alignment should match open parenthesis

with that
Reviewed-by: Avinesh Kumar <avinesh.kumar@suse.com>

>   		"len is smaller than the actual size");
>   }
>   

Regards,
Avinesh


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-02 17:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02  9:02 [LTP] [PATCH v2] gethostname02: Accept EOVERFLOW on alpha panzhe
2026-06-02 11:26 ` [LTP] " linuxtestproject.agent
2026-06-02 15:57 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp
2026-06-02 17:34 ` Avinesh Kumar via ltp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.