From: Cuishuangjin <YS.cuishuangjin@h3c.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Zhangchun <zhang.chunA@h3c.com>
Subject: [PATCH] scripts/recordmcount: Fix uninitialized memory in file_append realloc
Date: Mon, 2 Nov 2026 07:40:43 +0000 [thread overview]
Message-ID: <4129294f3fcf42bfb47bea9066a9a8b2@h3c.com> (raw)
The file_append() function uses realloc() to grow the buffer, but
realloc() doesn't zero the newly allocated memory. This can lead to
uninitialized data being written to the output file.
Fix this by:
1. Checking the realloc() return value for errors
2. Zeroing the newly allocated memory with memset()
Signed-off-by: cys43405 <YS.cuishuangjin@h3c.com>
---
scripts/recordmcount.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index 3e4f54799cc0..754690887f66 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -111,6 +111,7 @@ static ssize_t uwrite(void const *const buf, size_t const count)
size_t cnt = count;
off_t idx = 0;
void *p = NULL;
+ off_t old_size = 0;
file_updated = 1;
@@ -118,18 +119,20 @@ static ssize_t uwrite(void const *const buf, size_t const count)
off_t aoffset = (file_ptr + count) - file_end;
if (aoffset > file_append_size) {
+ old_size = file_append_size;
p = realloc(file_append, aoffset);
- if (!p)
+ if (!p) {
free(file_append);
+ perror("write");
+ file_append_cleanup();
+ mmap_cleanup();
+ return -1;
+ }
file_append = p;
file_append_size = aoffset;
+ memset(file_append + old_size, 0, aoffset - old_size);
}
- if (!file_append) {
- perror("write");
- file_append_cleanup();
- mmap_cleanup();
- return -1;
- }
+
if (file_ptr < file_end) {
cnt = file_end - file_ptr;
} else {
--
2.33.0
-------------------------------------------------------------------------------------------------------------------------------------
本邮件及其附件含有新华三集团的保密信息,仅限于发送给上面地址中列出的个人或群组。
禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。
如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
This e-mail and its attachments contain confidential information from New H3C, which is intended only for the person or entity whose address is listed above.
Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited.
If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!
reply other threads:[~2026-11-02 7:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4129294f3fcf42bfb47bea9066a9a8b2@h3c.com \
--to=ys.cuishuangjin@h3c.com \
--cc=linux-kernel@vger.kernel.org \
--cc=zhang.chunA@h3c.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
all inboxes | Powered by JetHome®