public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] Add open15 test
Date: Thu, 27 Jun 2024 11:49:15 +0200	[thread overview]
Message-ID: <Zn01m4CWFTQtL07t@yuki> (raw)
In-Reply-To: <20240220133254.16057-1-andrea.cervesato@suse.de>

Hi!
> --- /dev/null
> +++ b/testcases/kernel/syscalls/open/open15.c
> @@ -0,0 +1,101 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
> + *    Author: David Fenner
> + *    Copilot: Jon Hendrickson
> + * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that open() is working correctly on symlink()
> + * generated files.
> + */
> +
> +#include "tst_test.h"
> +
> +#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
> +
> +static char myfile_path[PATH_MAX];
> +
> +static void test_open_symlink(void)
> +{
> +	int fd;
> +	int str_size;
> +	char buff[128];
> +	char *symname = "my_symlink0";
> +
> +	str_size = strlen(BIG_STRING);
> +
> +	SAFE_SYMLINK(myfile_path, symname);
> +
> +	fd = SAFE_OPEN(symname, O_CREAT | O_RDWR, 0777);
> +	SAFE_WRITE(SAFE_WRITE_ALL, fd, BIG_STRING, str_size);


> +	SAFE_LSEEK(fd, 0, 0);
> +	SAFE_READ(1, fd, buff, str_size);
> +	SAFE_CLOSE(fd);
> +	TST_EXP_EXPR(!strncmp(buff, BIG_STRING, str_size),
> +		"symlink generated file can be opened to write data");
> +
> +	SAFE_UNLINK(symname);
> +	remove(myfile_path);

Here as well, SAFE_UNLINK()

> +}
> +
> +static void test_open_compare(void)
> +{
> +	int fd_file, fd_symlink;
> +	int str_size;
> +	char buff_file[128];
> +	char buff_symlink[128];
> +	char *symname = "my_symlink1";
> +
> +	str_size = strlen(BIG_STRING);
> +
> +	fd_file = SAFE_OPEN(myfile_path, O_CREAT | O_RDWR, 0777);
> +	SAFE_WRITE(SAFE_WRITE_ALL, fd_file, BIG_STRING, str_size);
> +
> +	SAFE_SYMLINK(myfile_path, symname);
> +
> +	SAFE_LSEEK(fd_file, 0, 0);
> +	SAFE_READ(1, fd_file, buff_file, str_size);
> +
> +	fd_symlink = SAFE_OPEN(symname, O_RDWR, 0777);
> +	SAFE_LSEEK(fd_symlink, 0, 0);
> +	SAFE_READ(1, fd_symlink, buff_symlink, str_size);
> +
> +	TST_EXP_EXPR(!strncmp(buff_file, buff_symlink, str_size),
> +		"file data is the equivalent to symlink generated file data");
> +
> +	SAFE_CLOSE(fd_file);
> +	SAFE_CLOSE(fd_symlink);
> +
> +	SAFE_UNLINK(symname);
> +	remove(myfile_path);

Here as well, SAFE_UNLINK()

> +}
> +
> +static void setup(void)
> +{
> +	int size;
> +	char *tmpdir;
> +
> +	tmpdir = tst_get_tmpdir();
> +	size = strlen(tmpdir);
> +
> +	myfile_path[size] = '/';
> +	memcpy(myfile_path, tmpdir, size);
> +	memcpy(myfile_path + size + 1, "myfile.txt", 6);

Here as well. This may overflow.

> +}
> +
> +static void run(void)
> +{
> +	test_open_symlink();
> +	test_open_compare();
> +}
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.test_all = run,
> +	.needs_tmpdir = 1,
> +};
> -- 
> 2.35.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

      reply	other threads:[~2024-06-27  9:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 13:32 [LTP] [PATCH v2] Add open15 test Andrea Cervesato
2024-06-27  9:49 ` Cyril Hrubis [this message]

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=Zn01m4CWFTQtL07t@yuki \
    --to=chrubis@suse.cz \
    --cc=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox