From 71831f01c40806756b6640591fca739c7790aebe Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 27 Feb 2018 18:02:21 -0500 Subject: [PATCH] Add various NULL pointer checks for good measure. --- src/apply-default-acl.c | 25 +++++++++++++++++++++++++ src/libadacl.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/apply-default-acl.c b/src/apply-default-acl.c index ea3ef64..bebb27c 100644 --- a/src/apply-default-acl.c +++ b/src/apply-default-acl.c @@ -9,6 +9,7 @@ #define _XOPEN_SOURCE 500 #define _GNU_SOURCE +#include /* EINVAL */ #include /* AT_FOO constants */ #include /* nftw() et al. */ #include /* getopt_long() */ @@ -67,6 +68,11 @@ bool path_accessible(const char* path) { * */ void usage(const char* program_name) { + if (program_name == NULL) { + /* ??? */ + return; + } + printf("Apply any applicable default ACLs to the given files or " "directories.\n\n"); printf("Usage: %s [flags] [ [ ...]]\n\n", @@ -96,6 +102,13 @@ int apply_default_acl_nftw(const char *target, int info, struct FTW *ftw) { + if (target == NULL) { + errno = EINVAL; + perror("apply_default_acl_nftw (args)"); + return ACL_ERROR; + } + + if (apply_default_acl_ex(target, sp, false) == ACL_ERROR) { /* I guess we do want to bail out for serious/unexpected errors? */ return ACL_ERROR; @@ -119,6 +132,12 @@ int apply_default_acl_nftw_x(const char *target, int info, struct FTW *ftw) { + if (target == NULL) { + errno = EINVAL; + perror("apply_default_acl_nftw_x (args)"); + return ACL_ERROR; + } + if (apply_default_acl_ex(target, sp, true) == ACL_ERROR) { /* I guess we do want to bail out for serious/unexpected errors? */ return ACL_ERROR; @@ -148,6 +167,12 @@ int apply_default_acl_nftw_x(const char *target, * then we return @c ACL_ERROR. Otherwise, we return @c ACL_SUCCESS. */ int apply_default_acl_recursive(const char *target, bool no_exec_mask) { + if (target == NULL) { + errno = EINVAL; + perror("apply_default_acl_recursive (args)"); + return ACL_ERROR; + } + int max_levels = 256; int flags = FTW_MOUNT | FTW_PHYS; diff --git a/src/libadacl.c b/src/libadacl.c index a192360..5402a32 100644 --- a/src/libadacl.c +++ b/src/libadacl.c @@ -56,8 +56,12 @@ * and @c OPEN_ERROR if not. */ int safe_open_ex(int at_fd, char* pathname, int flags) { - /* We're only called by safe_open(), so pathname is guaranteed to be - non-NULL */ + if (pathname == NULL) { + errno = EINVAL; + perror("safe_open_ex (args)"); + return OPEN_ERROR; + } + if (strlen(pathname) == 0) { /* Oops, went one level to deep with nothing to do. */ return at_fd; @@ -210,6 +214,11 @@ int safe_open(const char* pathname, int flags) { * */ int acl_set_entry(acl_t* aclp, acl_entry_t entry) { + if (aclp == NULL || entry == NULL) { + errno = EINVAL; + perror("acl_set_entry (args)"); + return ACL_ERROR; + } acl_tag_t entry_tag; if (acl_get_tag_type(entry, &entry_tag) == ACL_ERROR) { @@ -358,6 +367,11 @@ int acl_entry_count(acl_t acl) { * - @c ACL_ERROR - Unexpected library error */ int acl_is_minimal(acl_t acl) { + if (acl == NULL) { + errno = EINVAL; + perror("acl_is_minimal (args)"); + return ACL_ERROR; + } int ec = acl_entry_count(acl); @@ -388,6 +402,11 @@ int acl_is_minimal(acl_t acl) { * - @c ACL_ERROR - Unexpected library error. */ int acl_execute_masked(acl_t acl) { + if (acl == NULL) { + errno = EINVAL; + perror("acl_execute_masked (args)"); + return ACL_ERROR; + } acl_entry_t entry; int ge_result = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); @@ -451,6 +470,12 @@ int acl_execute_masked(acl_t acl) { * - @c ACL_ERROR - Unexpected library error. */ int any_can_execute(int fd, const struct stat* sp) { + if (sp == NULL) { + errno = EINVAL; + perror("any_can_execute (args)"); + return ACL_ERROR; + } + acl_t acl = acl_get_fd(fd); if (acl == (acl_t)NULL) { @@ -548,8 +573,7 @@ int any_can_execute(int fd, const struct stat* sp) { * - @c ACL_ERROR - Unexpected library error. */ int assign_default_acl(const char* path, acl_t acl) { - - if (path == NULL) { + if (path == NULL || acl == NULL) { errno = EINVAL; perror("assign_default_acl (args)"); return ACL_ERROR; -- 2.43.2