Skip to content

Conversation

jouae
Copy link
Contributor

@jouae jouae commented Mar 5, 2025

When executing the 'ih' or 'it' command with multiple leading spaces, the parsed arguments contained unexpected characters.

The problem stemmed from 'parse_args' allocating memory for 'buf' using 'malloc_or_fail', which does not initialize memory. Since 'strlen' determines string length based on the first null terminator it encounters, uninitialized memory beyond the expected input could be incorrectly read, leading to unintended characters in 'argv'.

To fix this, an explicit null terminator was added at the end of the parsing loop, ensuring proper null termination and preventing 'strlen' from reading beyond valid input.

This change guarantees correct argument parsing
even when the input contains multiple leading spaces.

Close #233

Change-Id: I178fa357962b28fd22646ab9c21542e1c780bd55

When executing the 'ih' or 'it' command with multiple leading spaces,
the parsed arguments contained unexpected characters.

The problem stemmed from 'parse_args' allocating memory for 'buf' using
'malloc_or_fail', which does not initialize memory. Since 'strlen'
determines string length based on the first null terminator
it encounters, uninitialized memory beyond the expected input could be
incorrectly read, leading to unintended characters in 'argv'.

To fix this, an explicit null terminator was added at the end of
the parsing loop, ensuring proper null termination and
preventing 'strlen' from reading beyond valid input.

This change guarantees correct argument parsing
even when the input contains multiple leading spaces.

Close sysprog21#233

Change-Id: I178fa357962b28fd22646ab9c21542e1c780bd55
@jouae
Copy link
Contributor Author

jouae commented Mar 5, 2025

Comparison of the effect of the PR as following:

Before:

cmd> ih              1
l = [1cU]

where string cU is an uninitialized value.

After:
cmd> ih              1
l = [1]

@jserv jserv merged commit b35d40b into sysprog21:master Mar 5, 2025
1 of 2 checks passed
@jserv
Copy link
Contributor

jserv commented Mar 5, 2025

Thank @jouae for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function parse_args parses incorrect arguments
2 participants