Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed handling of long strings when using INI_USE_STACK #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tyler92
Copy link

@tyler92 tyler92 commented Nov 23, 2022

Undefined behavior occurred if the incoming .ini file contains a line that is longer than INI_MAX_LINE with the INI_USE_STACK option. In such a case, it is safe to abort parsing even if INI_STOP_ON_FIRST_ERROR is not set.

See #145 for the details

Signed-off-by: Mikhail Khachayants tyler92@inbox.ru

Undefined behavior occurred if the incoming .ini file contains a
line that is longer than INI_MAX_LINE with the INI_USE_STACK
option. In such a case, it is safe to abort parsing even if
INI_STOP_ON_FIRST_ERROR is not set.

Signed-off-by: Mikhail Khachayants <tyler92@inbox.ru>
@tyler92
Copy link
Author

tyler92 commented Nov 23, 2022

I'm not sure about INI_STOP_ON_FIRST_ERROR and unit tests. I would appreciate a discussion on this.

Copy link
Owner

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments left. Yeah, we'd need to add tests for this. They're "diff tests", meaning they run a program and ensure the output hasn't changed against a file already committed.

See here for current failures.

@@ -156,6 +156,14 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,

lineno++;

#if INI_USE_STACK
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do this check whether or not INI_USE_STACK is set, right? Because even in non-stack mode we might have read and realloc'd up to INI_MAX_LINE bytes.

@@ -156,6 +156,14 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,

lineno++;

#if INI_USE_STACK
if (strlen(line) == max_line - 1 && line[max_line - 2] != '\n') {
/* Exit even if INI_STOP_ON_FIRST_ERROR is not set */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure about this. If INI_STOP_ON_FIRST_ERROR is false (the default), I think we should read and discard the rest of the current line, and then proceed. We could decide to do this as a stop-gap fix, but I'm not sure that's a good idea -- if we fix this I think we should do it properly in a single PR.

You can see how it's breaking the existing max-line tests as it is currently.

@tyler92
Copy link
Author

tyler92 commented Nov 24, 2022

OK, thanks for the comments. I'll rework my PR and will come back later.

@flysand7
Copy link

He never did lmao

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.

None yet

3 participants