public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] What is wrong with this program ?
@ 2020-04-28  9:47 Viresh Kumar
  2020-04-28  9:52 ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2020-04-28  9:47 UTC (permalink / raw)
  To: ltp

#include "tst_test.h"

static void run(void)
{
	int fd;

	fd = SAFE_OPEN("file", O_RDWR | O_CREAT);
	SAFE_CLOSE(fd);
	fd = SAFE_OPEN("file", O_RDWR | O_CREAT);
}

static struct tst_test test = {
	.test_all = run,
	.needs_tmpdir = 1,
};


It fails with:

safe_macros.c:230: BROK: foo.c:9: open(file,66,01) failed: EACCES (13)

if run as a normal user and passes with sudo.

-- 
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] What is wrong with this program ?
  2020-04-28  9:47 [LTP] What is wrong with this program ? Viresh Kumar
@ 2020-04-28  9:52 ` Cyril Hrubis
  2020-04-28 10:02   ` Viresh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2020-04-28  9:52 UTC (permalink / raw)
  To: ltp

Hi!
> #include "tst_test.h"
> 
> static void run(void)
> {
> 	int fd;
> 
> 	fd = SAFE_OPEN("file", O_RDWR | O_CREAT);
> 	SAFE_CLOSE(fd);
> 	fd = SAFE_OPEN("file", O_RDWR | O_CREAT);
> }
> 
> static struct tst_test test = {
> 	.test_all = run,
> 	.needs_tmpdir = 1,
> };
> 
> 
> It fails with:
> 
> safe_macros.c:230: BROK: foo.c:9: open(file,66,01) failed: EACCES (13)
> 
> if run as a normal user and passes with sudo.

I guess that you forget to pass the mode argument to the first
SAFE_OPEN() and hence the second one fails because the garbage passed to
mode prevents normal users from opening the file.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] What is wrong with this program ?
  2020-04-28  9:52 ` Cyril Hrubis
@ 2020-04-28 10:02   ` Viresh Kumar
  2020-04-28 10:09     ` Martin Doucha
  2020-04-28 11:49     ` Cyril Hrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Viresh Kumar @ 2020-04-28 10:02 UTC (permalink / raw)
  To: ltp

On 28-04-20, 11:52, Cyril Hrubis wrote:
> Hi!
> > #include "tst_test.h"
> > 
> > static void run(void)
> > {
> > 	int fd;
> > 
> > 	fd = SAFE_OPEN("file", O_RDWR | O_CREAT);
> > 	SAFE_CLOSE(fd);
> > 	fd = SAFE_OPEN("file", O_RDWR | O_CREAT);
> > }
> > 
> > static struct tst_test test = {
> > 	.test_all = run,
> > 	.needs_tmpdir = 1,
> > };
> > 
> > 
> > It fails with:
> > 
> > safe_macros.c:230: BROK: foo.c:9: open(file,66,01) failed: EACCES (13)
> > 
> > if run as a normal user and passes with sudo.
> 
> I guess that you forget to pass the mode argument to the first
> SAFE_OPEN() and hence the second one fails because the garbage passed to
> mode prevents normal users from opening the file.

Hmm, mode seems to be missing from a lot of syscall tests, which means that if
they are run in a loop (with the cmdline way you mentioned earlier), then they
will all fail.

-- 
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] What is wrong with this program ?
  2020-04-28 10:02   ` Viresh Kumar
@ 2020-04-28 10:09     ` Martin Doucha
  2020-04-28 11:49     ` Cyril Hrubis
  1 sibling, 0 replies; 5+ messages in thread
From: Martin Doucha @ 2020-04-28 10:09 UTC (permalink / raw)
  To: ltp

On 28. 04. 20 12:02, Viresh Kumar wrote:
> Hmm, mode seems to be missing from a lot of syscall tests, which 
> means that if they are run in a loop (with the cmdline way you 
> mentioned earlier), then they will all fail.

Allow me to quote from TFM:

> The mode argument specifies the file mode bits be applied when a new
> file is created. This argument must be supplied when O_CREAT or
> O_TMPFILE is specified in flags; if neither O_CREAT nor O_TMPFILE is
> specified, then mode is ignored. The effective mode is modified by
> the process's umask in the usual way: in the absence of a default
> ACL, the mode of the created file is (mode & ~umask). Note that this
> mode applies only to future accesses of the newly created file; the
> open() call that creates a read-only file may well return a
> read/write file descriptor.

-- 
Martin Doucha   mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] What is wrong with this program ?
  2020-04-28 10:02   ` Viresh Kumar
  2020-04-28 10:09     ` Martin Doucha
@ 2020-04-28 11:49     ` Cyril Hrubis
  1 sibling, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2020-04-28 11:49 UTC (permalink / raw)
  To: ltp

Hi!
> > > It fails with:
> > > 
> > > safe_macros.c:230: BROK: foo.c:9: open(file,66,01) failed: EACCES (13)
> > > 
> > > if run as a normal user and passes with sudo.
> > 
> > I guess that you forget to pass the mode argument to the first
> > SAFE_OPEN() and hence the second one fails because the garbage passed to
> > mode prevents normal users from opening the file.
> 
> Hmm, mode seems to be missing from a lot of syscall tests, which means that if
> they are run in a loop (with the cmdline way you mentioned earlier), then they
> will all fail.

If there is open() with O_CREAT without mode it's a bug.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-28 11:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-28  9:47 [LTP] What is wrong with this program ? Viresh Kumar
2020-04-28  9:52 ` Cyril Hrubis
2020-04-28 10:02   ` Viresh Kumar
2020-04-28 10:09     ` Martin Doucha
2020-04-28 11:49     ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox