lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <27bd9bc1-e7a5-4a81-91c9-2642feabb7ce@t-8ch.de>
Date:   Sun, 30 Jul 2023 00:17:24 +0200
From:   Thomas Weißschuh <thomas@...ch.de>
To:     Yuan Tan <tanyuan@...ylab.org>
Cc:     w@....eu, falcon@...ylab.org, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org
Subject: Re: [PATCH 2/2] selftests/nolibc: add testcase for pipe.

On 2023-07-25 14:01:30-0400, Yuan Tan wrote:
> Add a testcase of pipe that child process sends message to parent process.
> 
> Signed-off-by: Yuan Tan <tanyuan@...ylab.org>
> ---
>  tools/testing/selftests/nolibc/nolibc-test.c | 34 ++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 03b1d30f5507..43ba2884fd1e 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -767,6 +767,39 @@ int test_mmap_munmap(void)
>  	return ret;
>  }
>  
> +int test_pipe(void)
> +{
> +	int pipefd[2];
> +	char buf[32];
> +	pid_t pid;
> +	char *msg = "hello, nolibc";

const char * const

> +
> +	if (pipe(pipefd) == -1)
> +		return 1;
> +
> +	pid = fork();
> +
> +	switch (pid) {
> +	case -1:
> +		return 1;
> +
> +	case 0:
> +		close(pipefd[0]);
> +		write(pipefd[1], msg, strlen(msg));

Isn't this missing to write trailing the 0 byte?
Also check the return value.

> +		close(pipefd[1]);

Do we need to close the pipefds? The process is exiting anyways.

> +		exit(EXIT_SUCCESS);
> +
> +	default:
> +		close(pipefd[1]);
> +		read(pipefd[0], buf, 32);

Use sizeof(buf). Check return value == strlen(msg).

> +		close(pipefd[0]);
> +		wait(NULL);

waitpid(pid, NULL, 0);

> +
> +		if (strcmp(buf, msg))
> +			return 1;
> +		return 0;

return !!strcmp(buf, msg);

> +	}
> +}
>  
>  /* Run syscall tests between IDs <min> and <max>.
>   * Return 0 on success, non-zero on failure.
> @@ -851,6 +884,7 @@ int run_syscall(int min, int max)
>  		CASE_TEST(mmap_munmap_good);  EXPECT_SYSZR(1, test_mmap_munmap()); break;
>  		CASE_TEST(open_tty);          EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break;
>  		CASE_TEST(open_blah);         EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break;
> +		CASE_TEST(pipe);              EXPECT_SYSZR(1, test_pipe()); break;
>  		CASE_TEST(poll_null);         EXPECT_SYSZR(1, poll(NULL, 0, 0)); break;
>  		CASE_TEST(poll_stdout);       EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break;
>  		CASE_TEST(poll_fault);        EXPECT_SYSER(1, poll((void *)1, 1, 0), -1, EFAULT); break;
> -- 
> 2.39.2
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ