[LTP] [PATCH v4] getcwd01: Use syscall directly check invalid argument
Wei Gao
wegao@suse.com
Mon Dec 4 01:06:08 CET 2023
On Fri, Dec 01, 2023 at 11:14:15AM +0100, Petr Vorel wrote:
> Hi Wei,
>
> > Fixes: #1084
>
> > User 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
>
> ...
> > - 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.
I will try to send patch later.
Thanks you very much for fix my issue :) Will more carefull next time.
>
> Kind regards,
> Petr
More information about the ltp
mailing list