[prev in list] [next in list] [prev in thread] [next in thread] 

List:       oss-security
Subject:    AW: [oss-security] O_CREAT|O_DIRECTORY on nonexisting file expected behaviour?
From:       Fiedler Roman <Roman.Fiedler () ait ! ac ! at>
Date:       2014-11-26 19:32:42
Message-ID: 2ECE9D9EEF1F524185270138AE23265947D4894B () S0MSMAIL112 ! arc ! local
[Download RAW message or body]


> Von: Matthew Daley [mailto:mattd@bugfuzz.com]
>
> On Thu, Nov 27, 2014 at 4:28 AM, Fiedler Roman <Roman.Fiedler@ait.ac.at>
> wrote:
> > (...)
> > My test program was:
> >
> > #include <fcntl.h>
> > #include <stdio.h>
> > #include <sys/stat.h>
> >
> > int main(int argc, char **argv) {
> >   int fd;
> >   struct stat statBuf;
> >   int result;
> >
> >   fd=open("xxx", O_RDWR|O_CREAT|O_DIRECTORY, 0600);
> >   result=fstat(fd, &statBuf);
> >   if(result) {
> >     fprintf(stderr, "Stat failed\n");
> >     return(1);
> >   }
> >   fprintf(stderr, "New element type is %d\n", S_ISDIR(fd));
>
> FWIW, this should probably be S_ISDIR(statBuf.st_mode).

You are completely right, how stupid to miss that. I did not challenge the 
result, since it was the same as with "ls -al".

Also with S_ISDIR(statBuf.st_mode), result is the same, at least on my side.



#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>

int main(int argc, char **argv) {
  int fd;
  struct stat statBuf;
  int result;

  fd=open("xxx", O_RDWR|O_CREAT|O_DIRECTORY, 0600);
  result=fstat(fd, &statBuf);
  if(result) {
    fprintf(stderr, "Stat failed\n");
    return(1);
  }
  fprintf(stderr, "New element type is %d\n", S_ISDIR(statBuf.st_mode));
  return(0);
}


$ ./test
New element type is 0

["smime.p7s" (application/pkcs7-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic