Skip to content

Address sanitizer problem with mbsrtowcs #26657

@EvenOAndersen

Description

@EvenOAndersen

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 5.0.3 (285c424)
clang version 23.0.0git (https:/github.com/llvm/llvm-project e5927fecf8a6ce89e1a4eac5b828e7d42676452a)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/emsdk/upstream/bin

Failing command line in full:
emrun index.html
->

==42==T0: FakeStack created: 0x13030000 -- 0x130e1800 stack_size_log: 16; mmapped 710K, noreserve=0 [index.html:170:19](http://localhost:6931/index.html)
==42==T0: stack [0x1294d770,0x1295d770) size 0x10000; local=0x1295d74c [index.html:170:19](http://localhost:6931/index.html)
==42==LeakSanitizer: Dynamic linker not found. TLS and other allocations originating from linker might be falsely reported as leaks. [index.html:170:19](http://localhost:6931/index.html)
==42==AddressSanitizer Init done [index.html:170:19](http://localhost:6931/index.html)
================================================================= [index.html:170:19](http://localhost:6931/index.html)
==42==ERROR: AddressSanitizer: global-buffer-overflow on address 0x12494024 at pc 0x00007ab4 bp 0x1295d730 sp 0x1295d73c [index.html:170:19](http://localhost:6931/index.html)
READ of size 4 at 0x12494024 thread T0 [index.html:170:19](http://localhost:6931/index.html)
    #0 0x00007ab4  (this.program+0x7ab4) [index.html:170:19](http://localhost:6931/index.html)
    #1 0x0000184c  (this.program+0x184c) [index.html:170:19](http://localhost:6931/index.html)
    #2 0x00006611  (this.program+0x6611) [index.html:170:19](http://localhost:6931/index.html)
    #3 0x80000227 in createExportWrapper/< http://localhost:6931/index.js:551:12 [index.html:170:19](http://localhost:6931/index.html)
    #4 0x800012f8 in callMain http://localhost:6931/index.js:4856:28 [index.html:170:19](http://localhost:6931/index.html)
    #5 0x80001322 in doRun http://localhost:6931/index.js:4898:24 [index.html:170:19](http://localhost:6931/index.html)
    #6 0x80001329 in run/< http://localhost:6931/index.js:4905:7 [index.html:170:19](http://localhost:6931/index.html)
<empty string> [index.html:170:19](http://localhost:6931/index.html)
0x12494024 is located 60 bytes before global variable '.str.3' defined in 'main.cpp' (0x12494060) of size 2 [index.html:170:19](http://localhost:6931/index.html)
  '.str.3' is ascii string ' [index.html:170:19](http://localhost:6931/index.html)
' [index.html:170:19](http://localhost:6931/index.html)
0x12494024 is located 28 bytes before global variable '.str.2' defined in 'main.cpp' (0x12494040) of size 9 [index.html:170:19](http://localhost:6931/index.html)
  '.str.2' is ascii string ' Input: ' [index.html:170:19](http://localhost:6931/index.html)
0x12494025 is located 0 bytes after global variable '.str.1' defined in 'main.cpp' (0x12494020) of size 5 [index.html:170:19](http://localhost:6931/index.html)
  '.str.1' is ascii string 'url3' [index.html:170:19](http://localhost:6931/index.html)
SUMMARY: AddressSanitizer: global-buffer-overflow (this.program+0x7ab0) [index.html:170:19](http://localhost:6931/index.html)
Shadow bytes around the buggy address: [index.html:170:19](http://localhost:6931/index.html)
  0x12493d80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [index.html:170:19](http://localhost:6931/index.html)
  0x12493e00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [index.html:170:19](http://localhost:6931/index.html)
  0x12493e80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [index.html:170:19](http://localhost:6931/index.html)
  0x12493f00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [index.html:170:19](http://localhost:6931/index.html)
  0x12493f80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 [index.html:170:19](http://localhost:6931/index.html)
=>0x12494000: 00 04 f9 f9[05]f9 f9 f9 00 01 f9 f9 02 f9 f9 f9 [index.html:170:19](http://localhost:6931/index.html)
  0x12494080: 04 f9 f9 f9 05 f9 f9 f9 04 f9 f9 f9 04 f9 f9 f9 [index.html:170:19](http://localhost:6931/index.html)
  0x12494100: 04 f9 f9 f9 04 f9 f9 f9 04 f9 f9 f9 00 00 00 00 [index.html:170:19](http://localhost:6931/index.html)
  0x12494180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [index.html:170:19](http://localhost:6931/index.html)
  0x12494200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [index.html:170:19](http://localhost:6931/index.html)
  0x12494280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [index.html:170:19](http://localhost:6931/index.html)
Shadow byte legend (one shadow byte represents 8 application bytes): [index.html:170:19](http://localhost:6931/index.html)
  Addressable:           00 [index.html:170:19](http://localhost:6931/index.html)
  Partially addressable: 01 02 03 04 05 06 07 [index.html:170:19](http://localhost:6931/index.html)
  Heap left redzone:       fa [index.html:170:19](http://localhost:6931/index.html)
  Freed heap region:       fd [index.html:170:19](http://localhost:6931/index.html)
  Stack left redzone:      f1 [index.html:170:19](http://localhost:6931/index.html)
  Stack mid redzone:       f2 [index.html:170:19](http://localhost:6931/index.html)
  Stack right redzone:     f3 [index.html:170:19](http://localhost:6931/index.html)
  Stack after return:      f5 [index.html:170:19](http://localhost:6931/index.html)
  Stack use after scope:   f8 [index.html:170:19](http://localhost:6931/index.html)
  Global redzone:          f9 [index.html:170:19](http://localhost:6931/index.html)
  Global init order:       f6 [index.html:170:19](http://localhost:6931/index.html)
  Poisoned by user:        f7 [index.html:170:19](http://localhost:6931/index.html)
  Container overflow:      fc [index.html:170:19](http://localhost:6931/index.html)
  Array cookie:            ac [index.html:170:19](http://localhost:6931/index.html)
  Intra object redzone:    bb [index.html:170:19](http://localhost:6931/index.html)
  ASan internal:           fe [index.html:170:19](http://localhost:6931/index.html)
  Left alloca redzone:     ca [index.html:170:19](http://localhost:6931/index.html)
  Right alloca redzone:    cb [index.html:170:19](http://localhost:6931/index.html)
==42==ABORTING [index.html:170:19](http://localhost:6931/index.html)

Full link command and output with -v appended:
emcc main.cpp -o index.html -fsanitize=address --pre-js asan.js -v
->

/usr/local/emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/usr/local/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -fsanitize=address -v -c main.cpp -o /tmp/emscripten_temp_fsvux8tx/main.o
clang version 23.0.0git (https:/github.com/llvm/llvm-project e5927fecf8a6ce89e1a4eac5b828e7d42676452a)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/emsdk/upstream/bin
 (in-process)
 "/usr/local/emsdk/upstream/bin/clang-23" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/media/evenan/LaCie/lnx/source/repos/QTBUG/mbstate-bug -v -fcoverage-compilation-dir=/media/evenan/LaCie/lnx/source/repos/QTBUG/mbstate-bug -resource-dir /usr/local/emsdk/upstream/lib/clang/23 -D EMSCRIPTEN -isysroot /usr/local/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /usr/local/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/noeh/c++/v1 -internal-isystem /usr/local/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /usr/local/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /usr/local/emsdk/upstream/lib/clang/23/include -internal-isystem /usr/local/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /usr/local/emsdk/upstream/emscripten/cache/sysroot/include -fdeprecated-macro -ferror-limit 19 -fmessage-length=218 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -fsanitize=address -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -o /tmp/emscripten_temp_fsvux8tx/main.o -x c++ main.cpp
clang -cc1 version 23.0.0git based upon LLVM 23.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/local/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/noeh/c++/v1"
ignoring nonexistent directory "/usr/local/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/usr/local/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
 /usr/local/emsdk/upstream/emscripten/cache/sysroot/include/compat
 /usr/local/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
 /usr/local/emsdk/upstream/lib/clang/23/include
 /usr/local/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
 /usr/local/emsdk/upstream/bin/clang --version
 /usr/local/emsdk/upstream/bin/wasm-ld -o index.wasm /tmp/tmpuz8gdsnalibemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__lsan_disable --export=__lsan_enable --export=__asan_loadN --export=__asan_storeN --export=__funcs_on_exit --export=__wasm_call_ctors --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=69206016 --no-entry --no-stack-first --table-base=1 --global-base=306790400 /tmp/emscripten_temp_fsvux8tx/main.o -L/usr/local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -L/usr/local/emsdk/upstream/emscripten/src/lib -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lc-asan-debug -ldlmalloc-debug -lcompiler_rt -lc++-debug-noexcept -lc++abi-debug-noexcept -lsockets --whole-archive -lasan_rt --no-whole-archive -lubsan_rt -llsan_common_rt -lsanitizer_common_rt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr
 /usr/local/emsdk/upstream/bin/llvm-objcopy index.wasm index.wasm '--remove-section=llvm.func_attr.annotate.*' --remove-section=producers --remove-section=name '--remove-section=.debug*'
 /usr/local/emsdk/node/22.16.0_64bit/bin/node /usr/local/emsdk/upstream/emscripten/tools/compiler.mjs -
 /usr/local/emsdk/node/22.16.0_64bit/bin/node /usr/local/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs /tmp/emscripten_temp_fsvux8tx/index.js asanify --closure-friendly -o /tmp/emscripten_temp_fsvux8tx/index.jso1.js
 /usr/local/emsdk/node/22.16.0_64bit/bin/node /usr/local/emsdk/upstream/emscripten/tools/preprocessor.mjs - shell.html

main.cpp

asan.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions