From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from integral2.. (unknown [180.246.147.8]) by gnuweeb.org (Postfix) with ESMTPSA id 8A18B7E790; Tue, 26 Apr 2022 21:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1651008078; bh=2J5EuS3ECV20EJ65AsdktrAOFU9MBGyYkv7gn790rsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hoyAw8ugBoitrOnBRBIpzIQwvJaesiCLtOQwFW6XYjfSCAKou76iYPMr2FB04pEKm tFVF39a99x+hBRL27x/f7K+nLr1sqtUsT4n1NcxO8r0vdlNmLsWTN01lPQGJd3RcX5 fBd/6MZkSc1ZncIxYoBYpB7wAvq+D+oKk/VgqBc2MuY3g2F3sxn6oOWsZ7xDtxSGYX msbZdTfqFgy18rR9ItG8/AZHYE0HB98NJv/ppPLTf1VE3wb2snILcRbejjUgfHELUa GRTu3tCRIPc+vQSMqrT3PYnRul3RYE/hIlUIPnANlNVuGICF6aXnGH4ba8K6ZFCmuD rBLnrnbURr7KQ== From: Ammar Faizi To: Jens Axboe Cc: fio Mailing List , GNU/Weeb Mailing List , Ammar Faizi Subject: [PATCH v1 2/6] get_cgroup_root: Handle `ENOMEM` case on `malloc()` call Date: Wed, 27 Apr 2022 04:20:40 +0700 Message-Id: <20220426212044.78898-3-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220426212044.78898-1-ammarfaizi2@gnuweeb.org> References: <20220426212044.78898-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi Add error handling on malloc() call to prevent a NULL pointer dereference. Signed-off-by: Ammar Faizi --- cgroup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cgroup.c b/cgroup.c index 77e31a4d..b559b70f 100644 --- a/cgroup.c +++ b/cgroup.c @@ -114,6 +114,8 @@ void cgroup_kill(struct flist_head *clist) static char *get_cgroup_root(struct thread_data *td, struct cgroup_mnt *mnt) { char *str = malloc(64); + if (!str) + return NULL; if (td->o.cgroup) sprintf(str, "%s/%s", mnt->path, td->o.cgroup); @@ -178,6 +180,8 @@ int cgroup_setup(struct thread_data *td, struct flist_head *clist, struct cgroup * Create container, if it doesn't exist */ root = get_cgroup_root(td, *mnt); + if (!root) + return 1; if (mkdir(root, 0755) < 0) { int __e = errno; -- Ammar Faizi