aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamanta Navarro <ferivoz@riseup.net>2021-08-21 12:11:45 +0000
committerAndrew G. Morgan <morgan@kernel.org>2021-08-21 08:34:51 -0700
commit86c85c07c83f7ddc722b872ea0ff9e9b0f70bbc8 (patch)
tree3814a9f1c2b4abc8a38555cc3a382793701792a2
parent34186d026bad09e8e2bd9839bce138616c5d2557 (diff)
downloadlibcap-86c85c07c83f7ddc722b872ea0ff9e9b0f70bbc8.tar.gz
Check return values of allocating functions
The calloc and asprintf functions can return NULL if not enough memory is available. The majority of the code base checks for this condition already. Signed-off-by: Samanta Navarro <ferivoz@riseup.net> Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--libcap/cap_alloc.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libcap/cap_alloc.c b/libcap/cap_alloc.c
index 88ba6da..91813db 100644
--- a/libcap/cap_alloc.c
+++ b/libcap/cap_alloc.c
@@ -123,6 +123,10 @@ cap_t cap_dup(cap_t cap_d)
cap_iab_t cap_iab_init(void) {
__u32 *base = calloc(1, sizeof(__u32) + sizeof(struct cap_iab_s));
+ if (base == NULL) {
+ _cap_debug("out of memory");
+ return NULL;
+ }
*(base++) = CAP_IAB_MAGIC;
return (cap_iab_t) base;
}
@@ -138,6 +142,10 @@ cap_launch_t cap_new_launcher(const char *arg0, const char * const *argv,
const char * const *envp)
{
__u32 *data = calloc(1, sizeof(__u32) + sizeof(struct cap_launch_s));
+ if (data == NULL) {
+ _cap_debug("out of memory");
+ return NULL;
+ }
*(data++) = CAP_LAUNCH_MAGIC;
struct cap_launch_s *attr = (struct cap_launch_s *) data;
attr->arg0 = arg0;
@@ -156,6 +164,10 @@ cap_launch_t cap_new_launcher(const char *arg0, const char * const *argv,
cap_launch_t cap_func_launcher(int (callback_fn)(void *detail))
{
__u32 *data = calloc(1, sizeof(__u32) + sizeof(struct cap_launch_s));
+ if (data == NULL) {
+ _cap_debug("out of memory");
+ return NULL;
+ }
*(data++) = CAP_LAUNCH_MAGIC;
struct cap_launch_s *attr = (struct cap_launch_s *) data;
attr->custom_setup_fn = callback_fn;