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

iniparser_getboolean() can segfault on malformed config files #125

Closed
invd opened this issue Jun 19, 2020 · 6 comments · May be fixed by #139
Closed

iniparser_getboolean() can segfault on malformed config files #125

invd opened this issue Jun 19, 2020 · 6 comments · May be fixed by #139
Labels

Comments

@invd
Copy link

invd commented Jun 19, 2020

During recent fuzzing of the iniparser library via libFuzzer, I've discovered that iniparser can run into a segfault when parsing malformed configuration files.
As far as I can see, this is a local denial of service problem for some programs if attackers are able to provide or modify configuration files (and know which boolean configuration keys are fetched).

The following code position leads to the crash:

if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') {

Sanitizer crash info:

iniparser.c:561:9: runtime error: load of null pointer of type 'const char'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
iniparser.c:561:9 in
AddressSanitizer:DEADLYSIGNAL
=================================================================
==18912==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000055bd8c bp 0x7ffe80f4c070 sp 0x7ffe80f4bf80 T0)
==18912==The signal is caused by a READ memory access.
==18912==Hint: address points to the zero page.

The custom fuzzer harness is structured similarly to the iniexample.c example code. The relevant call after loading the target configuration tries to load the p:h key:

iniparser_getboolean(ini, "p:h", -1);

The following configuration file will lead to problems for the boolean fetch mentioned above:
[P:h]

Note: p:h was chosen arbitrarily as a shorter version of the pizza:ham key in the code example and has no special significance beyond that.

I've reported this finding privately to @ndevilla and @touilleMan.
@ndevilla has responded quickly and asked me to create a public issue report for it here.

philrandal added a commit to philrandal/iniparser that referenced this issue Jul 17, 2020
Add a null pointer check
dofuuz added a commit to dofuuz/iniparser that referenced this issue Jul 19, 2022
dofuuz added a commit to dofuuz/iniparser that referenced this issue Jul 19, 2022
@dofuuz
Copy link
Contributor

dofuuz commented Jul 19, 2022

There are similar problem in iniparser_getlongint() and iniparser_getdouble().

dofuuz added a commit to dofuuz/iniparser that referenced this issue Jul 20, 2022
- iniparser_getstring() returns `NULL` on some condition and it can cause crash
dofuuz added a commit to dofuuz/iniparser that referenced this issue Jul 20, 2022
- iniparser_getstring() returns `NULL` on some condition and it can cause crash
dofuuz added a commit to dofuuz/iniparser that referenced this issue Aug 23, 2022
- iniparser_getstring() returns `NULL` on some condition and it can cause crash
dofuuz added a commit to dofuuz/iniparser that referenced this issue Aug 23, 2022
- iniparser_getstring() returns `NULL` on some condition and it can cause crash
@lmoellendorf
Copy link
Collaborator

@invd

I tried to reproduce the issue without success. Maybe I am missing something.

Steps to reproduce:

  1. build current iniparser from master
  2. create file example.ini with this content:
[Pizza:ham]
  1. execute:
./example/iniexample ./example.ini

This is the result:

./example/iniexample ./example.ini
[pizza:ham]=UNDEF
Pizza:
Ham:       [-1]
Mushrooms: [-1]
Capres:    [-1]
Cheese:    [-1]
Wine:
Grape:     [UNDEF]
Year:      [-1]
Country:   [UNDEF]
Alcohol:   [-1]

There is no segfault. What am I missing?

@dofuuz
Copy link
Contributor

dofuuz commented Mar 18, 2024

@lmoellendorf
It was already fixed with #146

@invd
Copy link
Author

invd commented Mar 19, 2024

Good to see this is resolved now.

I'm trying to understand the reporting + patch history of this security issue.
It looks like

@ndevilla the v4.1 is very old, are you planning any new release?

@lmoellendorf
Copy link
Collaborator

@invd
Thank your for the summary.

Yes, @ndevilla is planning a new release and asked me to help me getting it ready.

The plan is to triage issues and bugs, do a first pass to correct the obvious, and create v4.2 ASAP.
All issues which are beyond bug fixing will have to wait for v5.

@ndevilla
Copy link
Owner

@lmoellendorf has kindly accepted to take the lead and process most issues and PRs on this project. Thanks a lot Lars!
The objective is to have a v4.2 release with known issues fixed, then move on to a v5 with possibly new features, breaking changes, a better build system, anything that would be needed. Hosting may move over to gitlab and this project frozen here as v4.2.

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