]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - src/libadacl.c
safe_open_ex: remove redundant (pathname == NULL) check.
[apply-default-acl.git] / src / libadacl.c
index d4e99aa2e48106ab51c806afc719f7890d2240c9..a1923601669b66efb0ffa45e62a9b73695354ddb 100644 (file)
@@ -40,6 +40,9 @@
  *   open a file descriptor in a symlink-safe way when combined with
  *   the @c O_NOFOLLOW flag.
  *
+ * The @c O_PATH flag is not used because we want to fail upon
+ * encountering any symlinks.
+ *
  * @param at_fd
  *   A file descriptor relative to which @c pathname will be opened.
  *
@@ -53,7 +56,9 @@
  *   and @c OPEN_ERROR if not.
  */
 int safe_open_ex(int at_fd, char* pathname, int flags) {
-  if (pathname != NULL && strlen(pathname) == 0) {
+  /* We're only called by safe_open(), so pathname is guaranteed to be
+     non-NULL */
+  if (strlen(pathname) == 0) {
     /* Oops, went one level to deep with nothing to do. */
     return at_fd;
   }
@@ -160,6 +165,11 @@ int safe_open(const char* pathname, int flags) {
   }
 
   int fd = open("/", flags);
+  if (fd == OPEN_ERROR) {
+    perror("safe_open (open)");
+    return OPEN_ERROR;
+  }
+
   if (strcmp(abspath, "/") == 0) {
     return fd;
   }