Skip to content

GitLab

    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
    • Menu
    Projects Groups Snippets
  • Sign up now
  • Login
  • Sign in / Register
  • P picoc
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 29
    • Issues 29
    • List
    • Boards
    • Service Desk
    • Milestones
    • Requirements
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Zik Saleeba
  • picoc
  • Issues
  • #44
Closed
Open
Created Sep 13, 2019 by Frederic Cambus@fcambus

Heap-based buffer overflow in the StringStrcpy() function

Hi,

While fuzzing picoc with Honggfuzz, I found a heap-based buffer overflow in the StringStrcpy() function, in cstdlib/string.c L10.

Attaching a reproducer: test01.c

Issue can be reproduced by running:

picoc test01.c
=================================================================
==14146==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x606000000532 at pc 0x0000004ad02c bp 0x7ffecf27b630 sp 0x7ffecf27ade0
WRITE of size 615 at 0x606000000532 thread T0
    #0 0x4ad02b in __interceptor_strcpy.part.245 (/home/fcambus/picoc/picoc+0x4ad02b)
    #1 0x55e547 in StringStrcpy /home/fcambus/picoc/cstdlib/string.c:10:33
    #2 0x53eb47 in ExpressionParseFunctionCall /home/fcambus/picoc/expression.c:1560:13
    #3 0x53bf47 in ExpressionParse /home/fcambus/picoc/expression.c:1251:17
    #4 0x5269ad in ParseStatement /home/fcambus/picoc/parse.c:653:13
    #5 0x52e5e4 in PicocParse /home/fcambus/picoc/parse.c:966:14
    #6 0x551d86 in PicocPlatformScanFile /home/fcambus/picoc/platform/platform_unix.c:131:5
    #7 0x514831 in main /home/fcambus/picoc/picoc.c:54:13
    #8 0x7fe7a057db96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #9 0x41bff9 in _start (/home/fcambus/picoc/picoc+0x41bff9)

0x606000000532 is located 0 bytes to the right of 50-byte region [0x606000000500,0x606000000532)
allocated by thread T0 here:
    #0 0x4dc0d8 in calloc (/home/fcambus/picoc/picoc+0x4dc0d8)
    #1 0x540af1 in HeapAllocMem /home/fcambus/picoc/heap.c:138:12
    #2 0x5471bb in VariableAlloc /home/fcambus/picoc/variable.c:73:20
    #3 0x547243 in VariableAllocValueAndData /home/fcambus/picoc/variable.c:91:30
    #4 0x54762b in VariableAllocValueFromType /home/fcambus/picoc/variable.c:110:30
    #5 0x5492ac in VariableDefine /home/fcambus/picoc/variable.c:272:23
    #6 0x54a403 in VariableDefineButIgnoreIdentical /home/fcambus/picoc/variable.c:341:20
    #7 0x52bf0f in ParseDeclaration /home/fcambus/picoc/parse.c:345:35
    #8 0x527415 in ParseStatement /home/fcambus/picoc/parse.c:772:38
    #9 0x52e5e4 in PicocParse /home/fcambus/picoc/parse.c:966:14
    #10 0x551d86 in PicocPlatformScanFile /home/fcambus/picoc/platform/platform_unix.c:131:5
    #11 0x514831 in main /home/fcambus/picoc/picoc.c:54:13
    #12 0x7fe7a057db96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/fcambus/picoc/picoc+0x4ad02b) in __interceptor_strcpy.part.245
Shadow bytes around the buggy address:
  0x0c0c7fff8050: 00 00 00 00 fa fa fa fa fd fd fd fd fd fd fd fa
  0x0c0c7fff8060: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa
  0x0c0c7fff8070: 00 00 00 00 00 00 00 00 fa fa fa fa fd fd fd fd
  0x0c0c7fff8080: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fa
  0x0c0c7fff8090: fa fa fa fa 00 00 00 00 00 00 00 00 fa fa fa fa
=>0x0c0c7fff80a0: 00 00 00 00 00 00[02]fa fa fa fa fa fa fa fa fa
  0x0c0c7fff80b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0c7fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0c7fff80d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0c7fff80e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0c7fff80f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==14146==ABORTING
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking