From: Wu Guanghao <wuguanghao3@huawei.com>
To: linux-ext4@vger.kernel.org,
"Благодаренко Артём" <artem.blagodarenko@gmail.com>
Cc: <liuzhiqiang26@huawei.com>, <linfeilong@huawei.com>
Subject: [PATCH V2 06/12] append_pathname: check the value returned by realloc to avoid segfault
Date: Mon, 31 May 2021 09:30:24 +0800 [thread overview]
Message-ID: <892d9908-2346-f410-3e25-87bd0b458a2e@huawei.com> (raw)
In-Reply-To: <00ad4a90-8a40-24c1-98d9-eb5f0da42436@huawei.com>
In append_pathname(), we need to add a new path to save the value returned by realloc,
otherwise the name->path may be NULL, causing segfault
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
contrib/fsstress.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/contrib/fsstress.c b/contrib/fsstress.c
index 2a983482..530bd920 100644
--- a/contrib/fsstress.c
+++ b/contrib/fsstress.c
@@ -599,7 +599,7 @@ void add_to_flist(int ft, int id, int parent)
void append_pathname(pathname_t * name, char *str)
{
int len;
-
+ char *path;
len = strlen(str);
#ifdef DEBUG
if (len && *str == '/' && name->len == 0) {
@@ -609,7 +609,13 @@ void append_pathname(pathname_t * name, char *str)
}
#endif
- name->path = realloc(name->path, name->len + 1 + len);
+ path = realloc(name->path, name->len + 1 + len);
+ if (path == NULL) {
+ fprintf(stderr, "fsstress: append_pathname realloc failed\n");
+ chdir(homedir);
+ abort();
+ }
+ name->path = path;
strcpy(&name->path[name->len], str);
name->len += len;
}
--
next prev parent reply other threads:[~2021-05-31 1:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-31 1:23 [PATCH V2 00/12] e2fsprogs: some bugfixs and some code cleanups Wu Guanghao
2021-05-31 1:26 ` [PATCH V2 03/12] zap_sector: fix memory leak Wu Guanghao
2021-05-31 1:28 ` [PATCH V2 04/12] ss_add_info_dir: fix memory leak and check whether,NULL pointer Wu Guanghao
2021-05-31 1:30 ` Wu Guanghao [this message]
2021-05-31 1:31 ` [PATCH V2 07/12] argv_parse: check return value of malloc in argv_parse() Wu Guanghao
2021-05-31 1:32 ` [PATCH V2 10/12] hashmap: change return value type of, ext2fs_hashmap_add() Wu Guanghao
2021-05-31 4:28 ` [PATCH V2 00/12] e2fsprogs: some bugfixs and some code cleanups Theodore Ts'o
[not found] ` <e4df8d8a-a5b2-a3cf-7e0d-c5dceb3b39f9@huawei.com>
2021-05-31 8:28 ` Wu Guanghao
2021-06-15 11:27 ` Zhiqiang Liu
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=892d9908-2346-f410-3e25-87bd0b458a2e@huawei.com \
--to=wuguanghao3@huawei.com \
--cc=artem.blagodarenko@gmail.com \
--cc=linfeilong@huawei.com \
--cc=linux-ext4@vger.kernel.org \
--cc=liuzhiqiang26@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox