All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: fio Mailing List <fio@vger.kernel.org>,
	GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>,
	Ammar Faizi <ammarfaizi2@gnuweeb.org>
Subject: [PATCH v2 2/6] cgroup: Handle `ENOMEM` case on `malloc()` call
Date: Wed, 27 Apr 2022 16:11:21 +0700	[thread overview]
Message-ID: <20220427091125.114146-3-ammarfaizi2@gnuweeb.org> (raw)
In-Reply-To: <20220427091125.114146-1-ammarfaizi2@gnuweeb.org>

Add error handling on `malloc()` call to prevent a NULL pointer
dereference.

Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 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


  parent reply	other threads:[~2022-04-27  9:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27  9:11 [PATCH v2 0/6] Small fio cleanups and fixes Ammar Faizi
2022-04-27  9:11 ` [PATCH v2 1/6] backend: Fix indentation Ammar Faizi
2022-04-27  9:11 ` Ammar Faizi [this message]
2022-04-27  9:11 ` [PATCH v2 3/6] stat: Handle `ENOMEM` case in `__show_run_stats()` Ammar Faizi
2022-04-27  9:35   ` Niklas Cassel
2022-04-27  9:52     ` Ammar Faizi
2022-04-27  9:11 ` [PATCH v2 4/6] engines/net: Replace `malloc()` + `memset()` with `calloc()` Ammar Faizi
2022-04-27  9:11 ` [PATCH v2 5/6] json: Change `if (!strlen(str))` to `if (!str[0])` Ammar Faizi
2022-04-27  9:11 ` [PATCH v2 6/6] Makefile: Suppress `-Wimplicit-fallthrough` when compiling `lex.yy` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220427091125.114146-3-ammarfaizi2@gnuweeb.org \
    --to=ammarfaizi2@gnuweeb.org \
    --cc=axboe@kernel.dk \
    --cc=fio@vger.kernel.org \
    --cc=gwml@vger.gnuweeb.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.