mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Alexey Izbyshev <izbyshev@ispras.ru>
Cc: musl@lists.openwall.com
Subject: Re: [musl] realpath without procfs -- should be ready for inclusion
Date: Wed, 25 Nov 2020 10:02:56 -0500	[thread overview]
Message-ID: <20201125150254.GG534@brightrain.aerifal.cx> (raw)
In-Reply-To: <a39bc2337c321df9015ef31bc03a868a@ispras.ru>

[-- Attachment #1: Type: text/plain, Size: 2839 bytes --]

On Tue, Nov 24, 2020 at 12:21:36PM +0300, Alexey Izbyshev wrote:
> On 2020-11-24 09:30, Rich Felker wrote:
> >I think before this goes upstream we should have a good set of
> >testcases that can be contributed to libc-test. Do you have ideas for
> >coverage? Some that come to mind:
> >
> Added some more ideas.
> 
> >- Absolute argument starting with /, //, and ///
> - Absolute argument equal to one of /, //, and ///
> >- Absolute symlink target starting with /, //, and ///
> - Absolute symlink target equal to one of /, //, and ///, with the
> link separated from the following component with /, //
> >- Final / after symlink-to-dir, dir, symlink-to-nondir, nondir
> - Intermediate / after symlink-to-nondir, nondir
> >- Final / in link contents after [the above]
> - Multiple / after ., .., normal component
> >- Initial .. in argument, cwd root or non-root
> >- Initial .. in symlink target, symlink in root or non-root
> >- Initial ...
> >- .. following symlink-to-dir, dir, symlink-to-nondir, nondir
> - . following symlink-to-dir, dir, symlink-to-nondir, nondir
> >- More .. than path depth
> >- Null argument
> >- Empty string argument
> - Argument consisting of a single ., ..
> >- Empty string link contents (testable only with seccomp hack)
> >- Argument valid abs path exact length PATH_MAX-1
> >- Argument valid rel path exact length PATH_MAX-1 to short abs path
> - Argument with PATH_MAX length (ENAMETOOLONG)
> - A relative symlink in the argument such that the length of the
> result is PATH_MAX-1 (valid path), PATH_MAX (ENAMETOOLONG)
> - An absolute symlink in the argument similar to the above
> - A relative argument with the current directory similar to the above
> - An argument consisting of a single (relative, absolute) symlink
> with the target having length PATH_MAX-1
> - An argument ending with a relative symlink with the target having
> length PATH_MAX-1 (ENAMETOOLONG)
> - An argument ending with an absolute symlink with the target having
> length PATH_MAX-1 (valid path)

OK, here are my WIP testcases. They only cover static cases, not
anything that depends on implementation-defined value of PATH_MAX or
how the working directory combines with tests to reach PATH_MAX.

The way you run the tests is by running ../setup.sh then ../checker.sh
from a scratch subdir of the dir containing the test files (realpath.c
also needs to be compiled and linked against the realpath impl you
want to test)

Format of the testcase file is one test per line, input and expected
output separated by whitespace. . and .. in expected output are
translated based on working dir. Error names are treated as output
since they don't fall in same namespace (no initial /).

All tests are currently passing for me.

If you have ideas for additional static tests that fit the form and
are easy to add, please suggest.

Rich

[-- Attachment #2: setup.sh --]
[-- Type: application/x-sh, Size: 434 bytes --]

[-- Attachment #3: checker.sh --]
[-- Type: application/x-sh, Size: 335 bytes --]

[-- Attachment #4: realpath.c --]
[-- Type: text/plain, Size: 510 bytes --]

#define _XOPEN_SOURCE 700
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <errno.h>

#define E(x) { x, #x }

static const struct {
	int ec;
	char *name;
} errs[] = { E(ENOENT), E(ENOTDIR), E(ENAMETOOLONG), E(ELOOP), E(EACCES), E(0) };

int main(int argc, char *argv[])
{
	while (*++argv) {
		char *s = realpath(*argv, (char[PATH_MAX]){""});
		//char *s = realpath(*argv, 0);
		if (!s) {
			int i;
			for (i=0; errs[i].ec && errs[i].ec!=errno; i++);
			s = errs[i].name;
		}
		puts(s);
	}
}

[-- Attachment #5: testcases.txt --]
[-- Type: text/plain, Size: 1158 bytes --]

/	/
//	//
///	/
/dev	/dev
/..	/
//..	//
///..	/
/dev/..	/
/dev/../..	/
/dev/../../..	/
dir	./dir
./dir	./dir
file	./file
./file	./file
noent	ENOENT
./noent	ENOENT
dir/	./dir
file/	ENOTDIR
noent/	ENOENT
link_to_dir/	./dir
link_to_file/	ENOTDIR
link_to_noent/	ENOENT
dir/..	.
file/..	ENOTDIR
noent/..	ENOENT
link_to_dir/..	.
link_to_file/.. ENOTDIR
link_to_noent/..	ENOENT
dlink_to_dir	./dir
dlink_to_file	ENOTDIR
dlink_to_noent	ENOENT
dlink_to_link_to_dir	./dir
dlink_to_link_to_file	ENOTDIR
dlink_to_link_to_noent	ENOENT
dlink_to_dir/	./dir
dlink_to_file/	ENOTDIR
dlink_to_noent/	ENOENT
dlink_to_link_to_dir/	./dir
dlink_to_link_to_file/	ENOTDIR
dlink_to_link_to_noent/	ENOENT
dlink_to_dir/..	.
dlink_to_file/..	ENOTDIR
dlink_to_noent/..	ENOENT
dlink_to_link_to_dir/..	.
dlink_to_link_to_file/..	ENOTDIR
dlink_to_link_to_noent/..	ENOENT
abs1	/
abs1/	/
abs1/dev	/dev
abs1/dev/	/dev
abs2	/
abs2/	/
abs2/dev	/dev
abs2/dev/	/dev
abs3	/
abs3/	/
abs3/dev	/dev
abs3/dev/	/dev
abs4	/
abs4/	/
abs4/dev	/dev
abs4/dev/	/dev
alt1	//
alt1/	//
alt1/.	//
alt2	//
alt2/	//
alt2/.	//
a	./a
a/..	.
...	./...
.../	./...
.../..	.
..	..
../	..
../.	..
a/../..	..
../noent	ENOENT

  parent reply	other threads:[~2020-11-25 15:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-22 22:56 Rich Felker
2020-11-23  2:03 ` Alexey Izbyshev
2020-11-23  3:17   ` Érico Nogueira
2020-11-23  3:34     ` Rich Felker
2020-11-23  3:19   ` Rich Felker
2020-11-23 18:56     ` Rich Felker
2020-11-23 20:53       ` Rich Felker
2020-11-24  3:39         ` Alexey Izbyshev
2020-11-24  4:26           ` Rich Felker
2020-11-24  5:13             ` Alexey Izbyshev
2020-11-24  6:30               ` Rich Felker
2020-11-24  9:21                 ` Alexey Izbyshev
2020-11-24 14:35                   ` Rich Felker
2020-11-24 20:17                     ` Rich Felker
2020-11-25 15:02                   ` Rich Felker [this message]
2020-11-25 19:40                     ` Alexey Izbyshev
2020-11-24 20:31             ` Rich Felker
2020-11-25  5:40               ` Alexey Izbyshev
2020-11-25 15:03                 ` Rich Felker
2020-11-24  3:41     ` Alexey Izbyshev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201125150254.GG534@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=izbyshev@ispras.ru \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).