makedumpfile: Bunch of fixes for --dump-dmesg
Subsystems (2)
cover makedumpfile: Bunch of fixes for --dump-dmesg
This patch series addresses several issues with the dump_log_entry() function.
Petr Tesarik (3):
Fix string append in dump_log_entry()
Prevent buffer overflow in dump_log_entry
Optimize one-character output in dump_log_entry
makedumpfile.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
Signature · 7 lines
1.8.4.5 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/3 Fix string append in dump_log_entry()
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.
--- makedumpfile.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
makedumpfile.c +7 -6
@@ -3866,7 +3866,7 @@ reset_bitmap_of_free_pages(unsigned long node_zones, struct cycle *cycle)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 ];
@@ -3881,18 +3881,19 @@ 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 (isprint (*p) ||isspace (*p)) -sprintf (buf,"%s%c" , buf, *p); + bufp =+sprintf (bufp,"%c" , *p);else -sprintf (buf,"%s\\x%02x" , buf, *p); + bufp +=sprintf (bufp,"\\x%02x" , *p); } -sprintf (buf,"%s\n" , buf); + bufp +=sprintf (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;
Signature · 7 lines
1.8.4.5 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/3 Prevent buffer overflow in dump_log_entry
In reply to Petr TesarikOne message may be longer than BUFSIZE. In that case, the output buffer overflows, causing stack corruption. Solve it by flushing the buffer when it gets full.
--- makedumpfile.c | 6 ++++++ 1 file changed, 6 insertions(+)
makedumpfile.c +6 -0
@@ -3885,6 +3885,12 @@ dump_log_entry(char *logptr, int fp) bufp +=sprintf (buf,"[%5lld.%06ld] " , nanos, rem/1000 );for (i =0 , p = msg; i < text_len; i++, p++) { +if (bufp - buf >=sizeof (buf) -6 ) { +if (write (info->fd_dumpfile, buf, bufp - buf) <0 ) +return FALSE; + bufp = buf; + } +if (isprint (*p) ||isspace (*p)) bufp =+sprintf (bufp,"%c" , *p);else
Signature · 7 lines
1.8.4.5 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 3/3 Optimize one-character output in dump_log_entry
In reply to Petr TesarikUsing sprintf to copy one character to the output buffer is overkill.
--- makedumpfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
makedumpfile.c +2 -2
@@ -3892,12 +3892,12 @@ dump_log_entry(char *logptr, int fp) }if (isprint (*p) ||isspace (*p)) - bufp =+sprintf (bufp,"%c" , *p); + *bufp++ = *p;else bufp +=sprintf (bufp,"\\x%02x" , *p); } - bufp +=sprintf (bufp,"\n" ); + *bufp++ ='\n' ;if (write (info->fd_dumpfile, buf, bufp - buf) <0 )return FALSE;
Signature · 7 lines
1.8.4.5 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hello Petr,
Quoted 10 lines
This patch series addresses several issues with the
dump_log_entry()function.Petr Tesarik (3):
Fix string append indump_log_entry()
Prevent buffer overflow indump_log_entry
Optimize one-character output indump_log_entry
makedumpfile.c| 19 +++++++++++++------1 file changed, 13 insertions(+), 6 deletions(-)
Looks good to me, I really appreciate your help !
Thanks
Atsushi Kumagai
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec