Skip to content

Commit 3a4035e

Browse files
authored
Fix wasi_path_open and add assertion to stringToUTF8 (#19127)
There were a few places where we were passing 0 instead of a string to `stringToUTF8`.
1 parent 578a13a commit 3a4035e

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

src/library_strings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ mergeInto(LibraryManager.library, {
156156
$stringToUTF8Array: function(str, heap, outIdx, maxBytesToWrite) {
157157
#if CAN_ADDRESS_2GB
158158
outIdx >>>= 0;
159+
#endif
160+
#if ASSERTIONS
161+
assert(typeof str === 'string');
159162
#endif
160163
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
161164
// undefined and false each don't write out any bytes.

src/library_wasi.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,11 @@ var WasiLibrary = {
449449
if (!(fd in preopens)) {
450450
return {{{ cDefs.EBADF }}};
451451
}
452-
var preopen = preopens[fd];
453-
stringToUTF8Array(preopens, HEAP8, path, path_len)
452+
var preopen_path = preopens[fd];
453+
stringToUTF8Array(preopen_path, HEAP8, path, path_len)
454+
#if SYSCALL_DEBUG
455+
dbg('fd_prestat_dir_name -> "' + preopen_path + '"');
456+
#endif
454457
return 0;
455458
},
456459

system/lib/compiler-rt/lib/asan/asan_flags.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void InitializeFlags() {
132132
#define MAKE_OPTION_LOAD(parser, name) \
133133
options = (char*)(long)EM_ASM_DOUBLE({ \
134134
return withBuiltinMalloc(function () { \
135-
return stringToNewUTF8(Module[name] || 0); \
135+
return stringToNewUTF8(Module[name] || ""); \
136136
}); \
137137
}); \
138138
parser.ParseString(options); \

system/lib/compiler-rt/lib/lsan/lsan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void InitializeFlags() {
8484
#if SANITIZER_EMSCRIPTEN
8585
char *options = (char*) EM_ASM_PTR({
8686
return withBuiltinMalloc(function () {
87-
return stringToNewUTF8(Module['LSAN_OPTIONS'] || 0);
87+
return stringToNewUTF8(Module['LSAN_OPTIONS'] || "");
8888
});
8989
});
9090
parser.ParseString(options);

system/lib/compiler-rt/lib/ubsan/ubsan_flags.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void InitializeFlags() {
7979
#if SANITIZER_EMSCRIPTEN
8080
char *options = (char*) EM_ASM_PTR({
8181
return withBuiltinMalloc(function () {
82-
return stringToNewUTF8(Module['UBSAN_OPTIONS'] || 0);
82+
return stringToNewUTF8(Module['UBSAN_OPTIONS'] || "");
8383
});
8484
});
8585
parser.ParseString(options);

0 commit comments

Comments
 (0)