Bug 1464635 - SEGV in chm_http
SEGV in chm_http
Status: NEW
Product: Fedora
Classification: Fedora
Component: chmlib (Show other bugs)
25
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Peter Lemenkov
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-06-23 22:26 EDT by Przemek Klosowski
Modified: 2017-06-23 22:36 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
chm file to demonstrate the crash (240.25 KB, application/octet-stream)
2017-06-23 22:26 EDT, Przemek Klosowski
no flags Details

  None (edit)
Description Przemek Klosowski 2017-06-23 22:26:26 EDT
Created attachment 1291319 [details]
chm file to demonstrate the crash

Description of problem:
chm_http gets frequent SEGV crashes

Version-Release number of selected component (if applicable):
chmlib-0.40-13.fc24.x86_64


How reproducible: every time


Steps to Reproduce:
1. run on a random .chm file:    chm_http e.chm
2. point browser to localhost:8080
3. click on links in the file

Actual results: segv crash
0x0000555555555654 in service_request (fd=<optimized out>, file=0x555555768010) at chm_http.c:357
357	    if (strncmp(end+1, "HTTP", 4) == 0)


Expected results: no crash, correct operation


Additional info: I suspect that it doesn't matter which .CHM file to use, but just in case, I include the one I tried to read
Comment 1 Przemek Klosowski 2017-06-23 22:36:35 EDT
The code in service_request():356 :
    end = strrchr(buffer, ' ');
    if (strncmp(end+1, "HTTP", 4) == 0)

is incorrect because strrchr() can return NULL if the string is not found, causing the NULL dereference in the next line.

I observed this when buffer is read as empty (i.e. it contains only NULLs).
The correct code should probably explicitly check for that null:

    end = strrchr(buffer, ' ');
    if (!end && strncmp(end+1, "HTTP", 4) == 0)

although in that case service_request() will produce a CONTENT_500 and I am not sure if that's warranted---it's unclear when the empty buffer will appear.

Note You need to log in before you can comment on or make changes to this bug.