Skip to content

Commit

Permalink
tst_kconfig: Avoid reporting buffer overflow when parsing /proc/cmdline
Browse files Browse the repository at this point in the history
When the test is run with a kernel booting with many parameters, the
buffer size is often not large enough to store the complete command
line. This results in a buffer overflow and the test complains with
the following message:

  tst_kconfig.c:609: TWARN: Buffer overflowed while parsing /proc/cmdline

Note:

Petr point out that these configs, which are generated by toolchain will
be longer than 128 chars someday, but I don't think that is the reason
we need raise our parsed buffer, since tst_kcmdline_parse() was just add
for popular parameter (which always pass by user and short). So far I
don't see any LTP test parse a longer parameters.

Fixes: 1808349 ("kconfig: add funtion to parse /proc/cmdline")
Signed-off-by: Li Wang <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
  • Loading branch information
wangli5665 committed Jun 20, 2024
1 parent 4828c64 commit e05bae6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/tst_kconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int tst_kconfig_check(const char *const kconfigs[]);
*/
struct tst_kcmdline_var {
const char *key;
char value[128];
char value[256];
bool found;
};

Expand Down
4 changes: 2 additions & 2 deletions lib/tst_kconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ char tst_kconfig_get(const char *confname)

void tst_kcmdline_parse(struct tst_kcmdline_var params[], size_t params_len)
{
char buf[128], line[512];
char buf[256], line[1024];
size_t b_pos = 0,l_pos =0, i;
int var_id = -1;

Expand Down Expand Up @@ -606,7 +606,7 @@ void tst_kcmdline_parse(struct tst_kcmdline_var params[], size_t params_len)
break;
default:
if (b_pos + 1 >= sizeof(buf)) {
tst_res(TWARN, "Buffer overflowed while parsing /proc/cmdline");
tst_res(TINFO, "WARNING: Buffer overflowed while parsing /proc/cmdline");
while (line[l_pos] != '\0' && line[l_pos] != ' ' && line[l_pos] != '\n')
l_pos++;

Expand Down

0 comments on commit e05bae6

Please sign in to comment.