Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Syscall param open(mode) contains uninitialised byte(s)" in open sys call

fd = open(pathname, O_WRONLY | O_LARGEFILE | O_APPEND | O_CREAT);

When running my tests I encounter a valgrind error:

==14280== Syscall param open(mode) contains uninitialised byte(s)
==14280==    at 0x4111084: open64 (open64.c:42)

And the return value of open is -2

Errno is set to 13 (Permission denied)

The pathname buffer contains:

0x68
0x72
0x32
0x2E
0x66
0x61
0x0 

Info about my system:

$ ls -la
drwxr-xr-x 7 rzetterberg zed 4096 Jul  4 13:56 .
$ id
uid=1000(rzetterberg) gid=1000(rzetterberg) groups=1000(rzetterberg), ... etc
$ sudo file -Ls /dev/sda1
/dev/sda1: sticky Linux rev 1.0 ext3 filesystem data, UUID=XXXX (needs journal recovery) (large files)
$ uname -a
Linux xxxx 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/Linux

Headers included:

#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

I don't understand how mode can have unitialised bytes and why I'm getting a Permission denied. It seems very strange to me!

like image 867
rzetterberg Avatar asked Oct 12 '25 19:10

rzetterberg


1 Answers

If you supply the O_CREAT flag to open(), you must supply a third argument. This is an integer which represents the permissions to apply to the created file (modified by the current umask).

like image 138
caf Avatar answered Oct 14 '25 07:10

caf