base: handle unsupported printf commands better

The commit consumes the argument of a unsupported printf command.

Without the commit - a subsequent command uses the argument of the preceding
command, which may cause memory corruption or page faults for sequences using
string commands, e.g.

Genode::printf("%#x %s\n", 0x20, "Test");

'#' is not supported by Genode::printf. In this scenario a pagefault at
address 0x20 is caused.

Fixes #1701
This commit is contained in:
Alexander Boettcher 2015-09-09 23:28:36 +02:00 committed by Christian Helmuth
parent 5309bda8b6
commit 9b21c88bc6
3 changed files with 7 additions and 0 deletions

View File

@ -335,6 +335,8 @@ void Console::vprintf(const char *format, va_list list)
case Format_command::INVALID:
_out_string("<warning: unsupported format string argument>");
/* consume the argument of the unsupported command */
va_arg(list, long);
break;
}

View File

@ -16,6 +16,10 @@
int main(int argc, char **argv)
{
/* test that unsupported commands don't crash the printf parser */
Genode::printf("%#x %s\n", 0x38, "test 1");
Genode::printf("%#lx %s\n", 0x38L, "test 2");
Genode::printf("-1 = %d = %ld\n", -1, -1L);
return 0;

View File

@ -55,3 +55,4 @@ stdcxx
nic_loopback
platform
report_rom
printf