Skip to content

Heap buffer overflow (read) while loading map in CRenderTools::RenderQuads, render_map.cpp:237 #2977

@mmmds

Description

@mmmds

The client crashes (only with ASAN) when an invalid map (10.map.zip) is loaded. Such a map can be delivered to the client by a malicious server.

Tested on Ubuntu 20.04 x86_64, Teeworlds version: f35da54b6f2c5f9fd4bbd4559f887ccf8f8cc526

Compilation with ASAN:

export CXXFLAGS="-ggdb -O0 -fsanitize=address -fno-omit-frame-pointer"
export CFLAGS="-ggdb -O0 -fsanitize=address -fno-omit-frame-pointer"
cmake ..
make

Run and connect to a server that delivers an invalid map:

./teeworlds "connect 127.0.0.1" "gfx_fullscreen 0" "gfx_screen_height 240" "gfx_screen_width 360"
[...]
=================================================================
==33614==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60b0000ea3b0 at pc 0x555555853cb1 bp 0x7fffffffb1e0 sp 0x7fffffffb1d0
READ of size 4 at 0x60b0000ea3b0 thread T0
    #0 0x555555853cb0 in CRenderTools::RenderQuads(CQuad*, int, int, void (*)(float, int, float*, void*), void*) /home/osboxes/teeworlds/teeworlds-asan/src/game/client/render_map.cpp:237
    #1 0x5555556f75f1 in CMapLayers::OnRender() /home/osboxes/teeworlds/teeworlds-asan/src/game/client/components/maplayers.cpp:375
    #2 0x555555827989 in CGameClient::OnRender() /home/osboxes/teeworlds/teeworlds-asan/src/game/client/gameclient.cpp:611
    #3 0x5555555fce4e in CClient::Render() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:796
    #4 0x5555555fce4e in CClient::Run() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:2131
    #5 0x5555555d24e5 in main /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:2704
    #6 0x7ffff68e10b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #7 0x5555555dc48d in _start (/home/osboxes/teeworlds/teeworlds-asan/build/teeworlds+0x8848d)

Address 0x60b0000ea3b0 is a wild pointer.
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/osboxes/teeworlds/teeworlds-asan/src/game/client/render_map.cpp:237 in CRenderTools::RenderQuads(CQuad*, int, int, void (*)(float, int, float*, void*), void*)
Shadow bytes around the buggy address:
  0x0c1680015420: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1680015430: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1680015440: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1680015450: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1680015460: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c1680015470: 04 fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa
  0x0c1680015480: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1680015490: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c16800154a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c16800154b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c16800154c0: 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
  Shadow gap:              cc
==33614==ABORTING

Doesn't crash without ASAN.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions