libc - bail out on invalid sem_open(3) flags
authorNicolas Thery <nthery@gmail.com>
Mon, 30 Jun 2014 18:57:27 +0000 (20:57 +0200)
committerNicolas Thery <nthery@gmail.com>
Mon, 30 Jun 2014 20:52:18 +0000 (22:52 +0200)
Preventing now callers from passing invalid flags prevents compatibility
issue should new flags be added to sem_open(3) in future standard
revisions.

Reviewed-by: joris@giovannangeli.fr
lib/libthread_xu/thread/thr_sem.c

index b7adee4..d957e49 100644 (file)
@@ -459,11 +459,17 @@ _sem_open(const char *name, int oflag, ...)
        fd = -1;
        sem = SEM_FAILED;
 
-       oflag = oflag & (O_CREAT | O_EXCL);
+       /*
+        * Bail out if invalid flags specified.
+        */
+       if (oflag & ~(O_CREAT|O_EXCL)) {
+               errno = EINVAL;
+               return (SEM_FAILED);
+       }
+
        oflag |= O_RDWR;
        oflag |= O_CLOEXEC;
 
-
        if (name == NULL) {
                errno = EINVAL;
                return (SEM_FAILED);