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

[crash] Null pointer dereference occurs when using -d #278

Closed
Ruanxingzhi opened this issue Dec 11, 2023 · 2 comments
Closed

[crash] Null pointer dereference occurs when using -d #278

Ruanxingzhi opened this issue Dec 11, 2023 · 2 comments

Comments

@Ruanxingzhi
Copy link

When running the program with -d and doc->code is null, a null pointer dereference occurs.

This bug affects versions 2.x and 3.0.0a.

Reproduce

Run:

./markdown -d -s ''

# or feed the program with three lines of "%"

echo -ne '%\n%\n%\n' | ./markdown -d

Result:

root@worklab ~/f/d/src (main) [1]# ./markdown -d -s ''
AddressSanitizer:DEADLYSIGNAL
=================================================================
==18163==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55f7546656fc bp 0x7ffdb5c70f10 sp 0x7ffdb5c70de0 T0)
==18163==The signal is caused by a READ memory access.
==18163==Hint: address points to the zero page.
    #0 0x55f7546656fc in mkd3_dump /root/fuzz/discount/src/dumptree.c:151:48
    #1 0x55f754649825 in main /root/fuzz/discount/src/main.c:366:11
    #2 0x7f4d3448d6c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #3 0x7f4d3448d784 in __libc_start_main csu/../csu/libc-start.c:360:3
    #4 0x55f7545713f0 in _start (/root/fuzz/discount/src/markdown+0x283f0) (BuildId: afc94b815b20ad8be244845d74b6694ea7bab3d9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/fuzz/discount/src/dumptree.c:151:48 in mkd3_dump
==18163==ABORTING

Reason

In function mkd_dump(), doc->code->next is used without check.

image

Possible fix

Add a check.

@Orc
Copy link
Owner

Orc commented Dec 12, 2023

Oh drat. Thank you for finding this annoying buglet. The code has been modified and now does the trivial test for non-null pointering before using the pointed to structure, and I've mirrored it here for
your verifying enjoyment.

@Ruanxingzhi
Copy link
Author

Verified. Thank you for the fix!

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

No branches or pull requests

2 participants