getcwd01: Only check buffer NULL on glibc
PATCH 1/1 getcwd01: Only check buffer NULL on glibc
--- testcases/kernel/syscalls/getcwd/getcwd01.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/getcwd/getcwd01.c +4 -1
@@ -34,10 +34,13 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, {buffer, 0, EINVAL}, {buffer, 1, ERANGE}, +/* musl and uclibc-ng will allocate memory before syscall if buf == NULL */ +#ifdef __GLIBC__ + {NULL, (size_t)-1, ENOMEM}, {NULL, 1, ERANGE} +#endif }; static void verify_getcwd(unsigned int n)
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hello,
Quoted 2 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>---
Need to mention the github issue in the commit
https://github.com/linux-test-project/ltp/issues/1084
Quoted 8 lines
testcases/kernel/syscalls/getcwd/getcwd01.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)testcases/kernel/syscalls/getcwd/getcwd01.c +0
-0
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 41
Quoted 9 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +3
-1@@ -34,10 +34,13 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, {buffer, 0, EINVAL}, {buffer, 1, ERANGE}, +/* musl and uclibc-ng will allocate memory before syscall if buf == NULL */ +#ifdef __GLIBC__ + {NULL, (size_t)-1, ENOMEM},
I'd prefer a more general solution. There are a lot of failures like this. I've seen a lot in the past in glibc where it changed its behaviour.
Most of these failures follow the same pattern:
pass an invalid argument -> expect a particular kernel error code.
Two things go wrong:
1. libc does something with the invalid value
a. performs some extended behaviour (like above)
b. segfaults
2. kernel returns an unexpected error code because the value or context are invalid in multiple ways.
For 1. we can usually call the system call directly. This solution has
been used before. It works for most syscalls except ones like clone.
For 2. Beyond reporting these errors I'm just going to ignore tests like this.
Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-0{NULL, 1, ERANGE} +#endif };static void verify_getcwd (unsigned int n)Signature · 1 line
2.35.3
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 getcwd01: Use syscall directly check invalid argument
In reply to Wei Gao via ltpRelated issue: https://github.com/linux-test-project/ltp/issues/1084
--- testcases/kernel/syscalls/getcwd/getcwd01.c | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd01.c +12 -11
@@ -14,8 +14,8 @@* * Expected Result: * 1) getcwd(2) should return NULL and set errno to EFAULT. -* 2) getcwd(2) should return NULL and set errno to ENOMEM. -* 3) getcwd(2) should return NULL and set errno to EINVAL. +* 2) getcwd(2) should return NULL and set errno to EFAULT. +* 3) getcwd(2) should return NULL and set errno to ERANGE. * 4) getcwd(2) should return NULL and set errno to ERANGE. * 5) getcwd(2) should return NULL and set errno to ERANGE. *
@@ -24,6 +24,7 @@#include <errno.h> #include <unistd.h> #include <limits.h> +#include "lapi/syscalls.h" #include "tst_test.h" static char buffer[5 ];
@@ -34,32 +35,32 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, - {buffer, 0, EINVAL}, + {NULL, (size_t)-1, EFAULT}, + {buffer, 0, ERANGE}, {buffer, 1, ERANGE}, {NULL, 1, ERANGE} }; +static void verify_getcwd (unsigned int n) {struct t_case *tc = &tcases[n]; -char *res; +int res; errno =0 ; - res =getcwd (tc->buf, tc->size); -TST_ERR = errno; -if (res) { + res =syscall (__NR_getcwd, tc->buf, tc->size); +if (!res) {tst_res (TFAIL ,"getcwd() succeeded unexpectedly" );return ; } -if (TST_ERR != tc->exp_err) { -tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , +if (errno != tc->exp_err) { +tst_res (TFAIL ,"getcwd() failed unexpectedly, expected %s" ,tst_strerrno (tc->exp_err));return ; } -tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +tst_res (TPASS ,"getcwd() failed as expected" ); } static struct tst_test test = {
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2] getcwd01: Use syscall directly check invalid argument
Hi Wei,
Yes, syscall(__NR_getcwd, ...) is way much better than #ifdef __GLIBC__ in v2.
Quoted 1 line
Related issue: https://github.com/linux-test-project/ltp/issues/1084
This should be Fixes: #1084
Quoted 51 lines
Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/getcwd/getcwd01.c | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-)testcases/kernel/syscalls/getcwd/getcwd01.c +7
-8@@ -14,8 +14,8 @@* * Expected Result: * 1) getcwd(2) should return NULL and set errno to EFAULT. -* 2) getcwd(2) should return NULL and set errno to ENOMEM. -* 3) getcwd(2) should return NULL and set errno to EINVAL. +* 2) getcwd(2) should return NULL and set errno to EFAULT. +* 3) getcwd(2) should return NULL and set errno to ERANGE. * 4) getcwd(2) should return NULL and set errno to ERANGE. * 5) getcwd(2) should return NULL and set errno to ERANGE. * @@ -24,6 +24,7 @@#include <errno.h> #include <unistd.h> #include <limits.h> +#include "lapi/syscalls.h" #include "tst_test.h" static char buffer[5 ];@@ -34,32 +35,32 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, - {buffer, 0, EINVAL}, + {NULL, (size_t)-1, EFAULT}, + {buffer, 0, ERANGE}, {buffer, 1, ERANGE}, {NULL, 1, ERANGE} }; + static void verify_getcwd(unsigned int n) { struct t_case *tc = &tcases[n]; - char *res; + int res; errno = 0; - res = getcwd(tc->buf, tc->size); - TST_ERR = errno; - if (res) {
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 58
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +4
-2+ res =syscall (__NR_getcwd, tc->buf, tc->size); +if (!res) {tst_res (TFAIL ,"getcwd() succeeded unexpectedly" );return ; } -if (TST_ERR != tc->exp_err) { - tst_res(TFAIL | TTERRNO, "getcwd() failed unexpectedly, expected %s", +if (errno != tc->exp_err) { + tst_res(TFAIL, "getcwd() failed unexpectedly, expected %s",
Hm, macros in tst_test_macros.h does not support char * (getcwd() returns NULL on failure. I wonder if we want to add TST_EXP_FAIL3(), or maybe macro with a better name (TST_EXP_FAIL_STR()).
Kind regards,
Petr
Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-1tst_strerrno(tc->exp_err));return ; } -tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +tst_res (TPASS ,"getcwd() failed as expected" ); }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2] getcwd01: Use syscall directly check invalid argument
Quoted 65 lines · Petr Vorel
Hi Wei,
Yes,
syscall(__NR_getcwd, ...)is way much better than #ifdef__GLIBC__in v2.Quoted 1 line
Related issue: https://github.com/linux-test-project/ltp/issues/1084
This should be Fixes: #1084
Quoted 56 lines
Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/getcwd/getcwd01.c | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-)testcases/kernel/syscalls/getcwd/getcwd01.c +9
-8@@ -14,8 +14,8 @@* * Expected Result: * 1) getcwd(2) should return NULL and set errno to EFAULT. -* 2) getcwd(2) should return NULL and set errno to ENOMEM. -* 3) getcwd(2) should return NULL and set errno to EINVAL. +* 2) getcwd(2) should return NULL and set errno to EFAULT. +* 3) getcwd(2) should return NULL and set errno to ERANGE. * 4) getcwd(2) should return NULL and set errno to ERANGE. * 5) getcwd(2) should return NULL and set errno to ERANGE. * @@ -24,6 +24,7 @@#include <errno.h> #include <unistd.h> #include <limits.h> +#include "lapi/syscalls.h" #include "tst_test.h" static char buffer[5 ];@@ -34,32 +35,32 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, - {buffer, 0, EINVAL}, + {NULL, (size_t)-1, EFAULT}, + {buffer, 0, ERANGE}, {buffer, 1, ERANGE}, {NULL, 1, ERANGE} }; + static void verify_getcwd(unsigned int n) { struct t_case *tc = &tcases[n]; - char *res; + int res; errno = 0; - res = getcwd(tc->buf, tc->size); - TST_ERR = errno; - if (res) { + res = syscall(__NR_getcwd, tc->buf, tc->size); + if (!res) { tst_res(TFAIL, "getcwd() succeeded unexpectedly"); return; }
Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 58
Quoted 4 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +2
-2-if (TST_ERR != tc->exp_err) { - tst_res(TFAIL | TTERRNO, "getcwd() failed unexpectedly, expected %s", +if (errno != tc->exp_err) { + tst_res(TFAIL, "getcwd() failed unexpectedly, expected %s",Hm, macros in
tst_test_macros.hdoes not support char * (getcwd()returns NULL on failure. I wonder if we want to addTST_EXP_FAIL3(), or maybe macro with a better name (TST_EXP_FAIL_STR()).
This case we can use TST_EXP_FAIL2 since syscall for __NR_getcwd will return the length of the buffer filled instead of char *.
Yes, we are missing macros to support char *, i think i can create one in another patch.
Quoted 11 lines
Kind regards,
PetrQuoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-1tst_strerrno(tc->exp_err));return ; } -tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +tst_res (TPASS ,"getcwd() failed as expected" ); }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 getcwd01: Use syscall directly check invalid argument
In reply to Wei Gao via ltp--- testcases/kernel/syscalls/getcwd/getcwd01.c | 27 ++++++--------------- 1 file changed, 7 insertions(+), 20 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd01.c +7 -20
@@ -14,8 +14,8 @@* * Expected Result: * 1) getcwd(2) should return NULL and set errno to EFAULT. -* 2) getcwd(2) should return NULL and set errno to ENOMEM. -* 3) getcwd(2) should return NULL and set errno to EINVAL. +* 2) getcwd(2) should return NULL and set errno to EFAULT. +* 3) getcwd(2) should return NULL and set errno to ERANGE. * 4) getcwd(2) should return NULL and set errno to ERANGE. * 5) getcwd(2) should return NULL and set errno to ERANGE. *
@@ -24,6 +24,7 @@#include <errno.h> #include <unistd.h> #include <limits.h> +#include "lapi/syscalls.h" #include "tst_test.h" static char buffer[5 ];
@@ -34,32 +35,18 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, - {buffer, 0, EINVAL}, + {NULL, (size_t)-1, EFAULT}, + {buffer, 0, ERANGE}, {buffer, 1, ERANGE}, {NULL, 1, ERANGE} }; +static void verify_getcwd (unsigned int n) {struct t_case *tc = &tcases[n]; -char *res; - - errno =0 ; - res =getcwd (tc->buf, tc->size); -TST_ERR = errno; -if (res) { -tst_res (TFAIL ,"getcwd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR != tc->exp_err) { -tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , -tst_strerrno (tc->exp_err)); -return ; - } -tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +TST_EXP_FAIL2 (syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err); } static struct tst_test test = {
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] getcwd01: Use syscall directly check invalid argument
Quoted 1 line
Fixes #1084
You haven't written the reason for switching to raw syscall syscall(__NR_getcwd, ...). (Adding https://github.com/linux-test-project/ltp/issues/1084 is not enough, the reason for the change is important enough to write to the commit message).
Also, raw syscall obviously returns a different errnos than glibc wrapper. But again, it would be better to document in the commit message the reason for the errno change.
Quoted 52 lines
Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/getcwd/getcwd01.c | 27 ++++++--------------- 1 file changed, 7 insertions(+), 20 deletions(-)testcases/kernel/syscalls/getcwd/getcwd01.c +6
-12@@ -14,8 +14,8 @@* * Expected Result: * 1) getcwd(2) should return NULL and set errno to EFAULT. -* 2) getcwd(2) should return NULL and set errno to ENOMEM. -* 3) getcwd(2) should return NULL and set errno to EINVAL. +* 2) getcwd(2) should return NULL and set errno to EFAULT. +* 3) getcwd(2) should return NULL and set errno to ERANGE. * 4) getcwd(2) should return NULL and set errno to ERANGE. * 5) getcwd(2) should return NULL and set errno to ERANGE. * @@ -24,6 +24,7 @@#include <errno.h> #include <unistd.h> #include <limits.h> +#include "lapi/syscalls.h" #include "tst_test.h" static char buffer[5 ];@@ -34,32 +35,18 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, - {buffer, 0, EINVAL}, + {NULL, (size_t)-1, EFAULT}, + {buffer, 0, ERANGE}, {buffer, 1, ERANGE}, {NULL, 1, ERANGE} }; + static void verify_getcwd(unsigned int n) { struct t_case *tc = &tcases[n]; - char *res; - - errno = 0; - res = getcwd(tc->buf, tc->size); - TST_ERR = errno; - if (res) { - tst_res(TFAIL, "getcwd() succeeded unexpectedly"); - return;
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 49
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-8- } - -if (TST_ERR != tc->exp_err) { -tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , -tst_strerrno (tc->exp_err)); -return ; - } -tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +TST_EXP_FAIL2 (syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err);
If the reason is that getcwd() wrapper in musl is not easily fixable (we probably don't want #ifdef __GLIBC__), I'm ok for this.
OTOH if test would be easily fixable for musl, we could consider testing both raw syscall and libc wrapper via .test_variants (separate effort).
Kind regards,
Petr
Quoted 3 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +0
-0}static struct tst_test test = {
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] getcwd01: Use syscall directly check invalid argument
Quoted 9 lines · Petr Vorel
Quoted 1 line
Fixes #1084You haven't written the reason for switching to raw syscall
syscall(__NR_getcwd, ...). (Adding https://github.com/linux-test-project/ltp/issues/1084 is not enough, the reason for the change is important enough to write to the commit message).Also, raw syscall obviously returns a different errnos than glibc wrapper. But again, it would be better to document in the commit message the reason for the errno change.
I add more comments in patchv4 for improvement.
Quoted 11 lines
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +0
-10-if (res) { -tst_res (TFAIL ,"getcwd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR != tc->exp_err) { -tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , -tst_strerrno (tc->exp_err)); -return ; - }
Quoted 8 lines
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 49
Quoted 2 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-1-tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +TST_EXP_FAIL2 (syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err);If the reason is that
getcwd()wrapper in musl is not easily fixable (we probably don't want #ifdef__GLIBC__), I'm ok for this.OTOH if test would be easily fixable for musl, we could consider testing both raw syscall and libc wrapper via .test_variants (separate effort).
I think we can add extra variant such as LIB_TYPE into t_case and use it to go different check logic. But we can not completely avoid use macro to identify musl or not if i understand correctly.
Quoted 7 lines
Kind regards,
PetrQuoted 3 lines
}
static struct
tst_testtest = {
Regards
Gao Wei
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] getcwd01: Use syscall directly check invalid argument
In reply to Wei Gao via ltpHi,
testcases/kernel/syscalls/getcwd/getcwd01.c line 18
Quoted 9 lines
+++
b/testcases/kernel/syscalls/getcwd/getcwd01.ctestcases/kernel/syscalls/getcwd/getcwd01.c +2
-2@@ -14,8 +14,8 @@* * Expected Result: * 1) getcwd(2) should return NULL and set errno to EFAULT. -* 2) getcwd(2) should return NULL and set errno to ENOMEM. -* 3) getcwd(2) should return NULL and set errno to EINVAL. +* 2) getcwd(2) should return NULL and set errno to EFAULT. +* 3) getcwd(2) should return NULL and set errno to ERANGE.
NOTE: actually before this change we tested getcwd(3), 2 is for raw syscalls, 3 for libc wrappers.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/1 getcwd01: Use syscall directly check invalid argument
In reply to Wei Gao via ltpUser space wrap getcwd with different implementation, for example glibc will directly input parameter into kernel in normal situation but uclibc-ng and musl will malloc buffer when buffer is NULL, so for uclibc and musl the parameter size will be ignored. Use system call directly check invalid argument can be a solution.
--- testcases/kernel/syscalls/getcwd/getcwd01.c | 27 ++++++--------------- 1 file changed, 7 insertions(+), 20 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd01.c +7 -20
@@ -14,8 +14,8 @@* * Expected Result: * 1) getcwd(2) should return NULL and set errno to EFAULT. -* 2) getcwd(2) should return NULL and set errno to ENOMEM. -* 3) getcwd(2) should return NULL and set errno to EINVAL. +* 2) getcwd(2) should return NULL and set errno to EFAULT. +* 3) getcwd(2) should return NULL and set errno to ERANGE. * 4) getcwd(2) should return NULL and set errno to ERANGE. * 5) getcwd(2) should return NULL and set errno to ERANGE. *
@@ -24,6 +24,7 @@#include <errno.h> #include <unistd.h> #include <limits.h> +#include "lapi/syscalls.h" #include "tst_test.h" static char buffer[5 ];
@@ -34,32 +35,18 @@ static struct t_case {int exp_err; } tcases[] = { {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, ENOMEM}, - {buffer, 0, EINVAL}, + {NULL, (size_t)-1, EFAULT}, + {buffer, 0, ERANGE}, {buffer, 1, ERANGE}, {NULL, 1, ERANGE} }; +static void verify_getcwd (unsigned int n) {struct t_case *tc = &tcases[n]; -char *res; - - errno =0 ; - res =getcwd (tc->buf, tc->size); -TST_ERR = errno; -if (res) { -tst_res (TFAIL ,"getcwd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR != tc->exp_err) { -tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , -tst_strerrno (tc->exp_err)); -return ; - } -tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +TST_EXP_FAIL2 (syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err); } static struct tst_test test = {
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4] getcwd01: Use syscall directly check invalid argument
Hi Wei,
Quoted 7 lines
Fixes #1084User space wrap getcwd with different implementation, for example glibc will directly input parameter into kernel in normal situation but uclibc-ng and musl will malloc buffer when buffer is NULL, so for uclibc and musl the parameter size will be ignored. Use system call directly check invalid argument can be a solution.
For the sake of the correctness: there is no malloc() in musl [1] (nor in the mirror source you posted to #1084), that's only in uclibc-ng [2] and glibc [3].
The reason why musl failed was already described by Richie and Cyril in #1084:
musl ignores the size parameter when buffer is NULL and allocates it with PATH_MAX and passes this size to kernel.
Therefore I reword the commit message.
[1] https://git.musl-libc.org/cgit/musl/tree/src/unistd/getcwd.c
[2] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/getcwd.c#n38
[3] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getcwd.c;h=5b0b6879ed28f278f07ce494f9be30f504757daa;hb=HEAD#l47
...
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 49
Quoted 2 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-1-tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +TST_EXP_FAIL2 (syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err);
While syscalls() would work everywhere, it's better is LTP wrapper tst_syscall() (it TCONF in case when syscall is not implemented which is I admit nearly impossible).
I used that and merged.
Thank you!
NOTE: we should implement .test_variants, where you just skip affected NULL buffer test (it's enough to test it with raw syscall). Please send a patch or let me know that you don't plan to do it and I'll do it.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4] getcwd01: Use syscall directly check invalid argument
Quoted 30 lines · Petr Vorel
Hi Wei,
Quoted 7 lines
Fixes #1084User space wrap getcwd with different implementation, for example glibc will directly input parameter into kernel in normal situation but uclibc-ng and musl will malloc buffer when buffer is NULL, so for uclibc and musl the parameter size will be ignored. Use system call directly check invalid argument can be a solution.
For the sake of the correctness: there is no
malloc()in musl [1] (nor in the mirror source you posted to #1084), that's only in uclibc-ng [2] and glibc [3].The reason why musl failed was already described by Richie and Cyril in #1084:
musl ignores the size parameter when buffer is NULL and allocates it withPATH_MAXand passes this size to kernel.Therefore I reword the commit message.
[1] https://git.musl-libc.org/cgit/musl/tree/src/unistd/getcwd.c
[2] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/getcwd.c#n38
[3] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getcwd.c;h=5b0b6879ed28f278f07ce494f9be30f504757daa;hb=HEAD#l47...
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 49
Quoted 2 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-1-tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +TST_EXP_FAIL2 (syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err);While
syscalls()would work everywhere, it's better is LTP wrappertst_syscall()(it TCONF in case when syscall is not implemented which is I admit nearly impossible).
Quoted 6 lines
I used that and merged.
Thank you!NOTE: we should implement .test_variants, where you just skip affected NULL buffer test (it's enough to test it with raw syscall). Please send a patch or let me know that you don't plan to do it and I'll do it.
I will try to send patch later.
Thanks you very much for fix my issue :) Will more carefull next time.
Quoted 3 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp