dump_log_entry() (bnc#865596). - makedumpfile-kernel-3.12-supported.patch: Mark kernel 3.12 as supported. OBS-URL: https://build.opensuse.org/package/show/Kernel:kdump/makedumpfile?expand=0&rev=78
65 lines
1.8 KiB
Diff
65 lines
1.8 KiB
Diff
From: Petr Tesarik <ptesarik@suse.cz>
|
|
Subject: Fix string append in dump_log_entry()
|
|
References: bnc#865596
|
|
Patch-mainline: not yet
|
|
|
|
To quote the sprintf(3) man page:
|
|
|
|
Some programs imprudently rely on code such as the following
|
|
|
|
sprintf(buf, "%s some further text", buf);
|
|
|
|
to append text to buf. However, the standards explicitly note that
|
|
the results are undefined if source and destination buffers overlap
|
|
when calling sprintf(), snprintf(), vsprintf(), and vsnprintf().
|
|
Depending on the version of gcc(1) used, and the compiler options
|
|
employed, calls such as the above will not produce the expected results.
|
|
|
|
It's also overkill to call sprintf() for something that can be done
|
|
with a simple assignment.
|
|
|
|
Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
|
|
---
|
|
makedumpfile.c | 15 ++++++++-------
|
|
1 file changed, 8 insertions(+), 7 deletions(-)
|
|
|
|
--- a/makedumpfile.c
|
|
+++ b/makedumpfile.c
|
|
@@ -3830,7 +3830,7 @@ reset_bitmap_of_free_pages(unsigned long
|
|
static int
|
|
dump_log_entry(char *logptr, int fp)
|
|
{
|
|
- char *msg, *p;
|
|
+ char *msg, *p, *bufp;
|
|
unsigned int i, text_len;
|
|
unsigned long long ts_nsec;
|
|
char buf[BUFSIZE];
|
|
@@ -3845,20 +3845,21 @@ dump_log_entry(char *logptr, int fp)
|
|
|
|
msg = logptr + SIZE(printk_log);
|
|
|
|
- sprintf(buf, "[%5lld.%06ld] ", nanos, rem/1000);
|
|
+ bufp = buf;
|
|
+ bufp += sprintf(buf, "[%5lld.%06ld] ", nanos, rem/1000);
|
|
|
|
for (i = 0, p = msg; i < text_len; i++, p++) {
|
|
if (*p == '\n')
|
|
- sprintf(buf, "%s.", buf);
|
|
+ *bufp++ = '.';
|
|
else if (isprint(*p) || isspace(*p))
|
|
- sprintf(buf, "%s%c", buf, *p);
|
|
+ *bufp++ = *p;
|
|
else
|
|
- sprintf(buf, "%s.", buf);
|
|
+ *bufp++ = '.';
|
|
}
|
|
|
|
- sprintf(buf, "%s\n", buf);
|
|
+ *bufp++ = '\n';
|
|
|
|
- if (write(info->fd_dumpfile, buf, strlen(buf)) < 0)
|
|
+ if (write(info->fd_dumpfile, buf, bufp - buf) < 0)
|
|
return FALSE;
|
|
else
|
|
return TRUE;
|