#define _GNU_SOURCE #define _FORTIFY_SOURCE 2 #include #include #include volatile int l0, l1; int open_test (void) { if (open ("a", O_CREAT | O_RDWR, 0644) == -1) abort (); if (open ("b", O_RDWR, 0755) == -1) abort (); if (open ("c", O_WRONLY) == -1) abort (); if (open ("d", l0 + O_CREAT | O_RDWR, 0600) == -1) abort (); if (open ("e", l0 + O_RDWR, 0700) == -1) abort (); if (open ("f", l0 + O_WRONLY) == -1) abort (); /* Invalid use of open, but only detectable at runtime. */ if (open ("g", l1 + O_CREAT | O_RDWR) == -1) abort (); return 0; } int open64_test (void) { if (open64 ("a", O_CREAT | O_RDWR, 0644) == -1) abort (); if (open64 ("b", O_RDWR, 0755) == -1) abort (); if (open64 ("c", O_WRONLY) == -1) abort (); if (open64 ("d", l0 + O_CREAT | O_RDWR, 0600) == -1) abort (); if (open64 ("e", l0 + O_RDWR, 0700) == -1) abort (); if (open64 ("f", l0 + O_WRONLY) == -1) abort (); /* Invalid use of open, but only detectable at runtime. */ if (open64 ("g", l1 + O_CREAT | O_RDWR) == -1) abort (); return 0; } int openat_test (int fd) { if (openat (fd, "a", O_CREAT | O_RDWR, 0644) == -1) abort (); if (openat (fd, "b", O_RDWR, 0755) == -1) abort (); if (openat (fd, "c", O_WRONLY) == -1) abort (); if (openat (fd, "d", l0 + O_CREAT | O_RDWR, 0600) == -1) abort (); if (openat (fd, "e", l0 + O_RDWR, 0700) == -1) abort (); if (openat (fd, "f", l0 + O_WRONLY) == -1) abort (); /* Invalid use of open, but only detectable at runtime. */ if (openat (fd, "g", l1 + O_CREAT | O_RDWR) == -1) abort (); return 0; } int openat64_test (int fd) { if (openat64 (fd, "a", O_CREAT | O_RDWR, 0644) == -1) abort (); if (openat64 (fd, "b", O_RDWR, 0755) == -1) abort (); if (openat64 (fd, "c", O_WRONLY) == -1) abort (); if (openat64 (fd, "d", l0 + O_CREAT | O_RDWR, 0600) == -1) abort (); if (openat64 (fd, "e", l0 + O_RDWR, 0700) == -1) abort (); if (openat64 (fd, "f", l0 + O_WRONLY) == -1) abort (); /* Invalid use of open, but only detectable at runtime. */ if (openat64 (fd, "g", l1 + O_CREAT | O_RDWR) == -1) abort (); return 0; } int mqopen_test (void) { if (mq_open ("/a", O_CREAT | O_RDWR, 0644, NULL) == -1) abort (); if (mq_open ("/b", O_RDWR, 0755, NULL) != -1) abort (); if (mq_open ("/c", O_WRONLY) != -1) abort (); if (mq_open ("/d", l0 + O_CREAT | O_RDWR, 0600, NULL) == -1) abort (); if (mq_open ("/e", l0 + O_RDWR, 0700, NULL) != -1) abort (); if (mq_open ("/f", l0 + O_WRONLY) != -1) abort (); /* Invalid use of open, but only detectable at runtime. */ if (mq_open ("/g", l1 + O_CREAT | O_RDWR) != -1) abort (); return 0; } int main (void) { int fd = open (".", O_DIRECTORY | O_RDONLY); l1 = -O_CREAT; open_test (); open64_test (); openat_test (fd); openat64_test (fd); mqopen_test (); l1 = 0; return 0; }