Skip to content

Commit 5ef8969

Browse files
committed
wasmtime: harden wasm_interpret_header func
Signed-off-by: Maximilian Hüter <[email protected]>
1 parent 2170c02 commit 5ef8969

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/libcrun/handlers/handler-utils.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ wasm_can_handle_container (libcrun_container_t *container, libcrun_error_t *err
7272
}
7373

7474
wasm_encoding_t
75-
wasm_interpete_header (const char *header)
75+
wasm_interpret_header (const char *header, const size_t len)
7676
{
77+
if (len < 8)
78+
return WASM_ENC_INVALID;
79+
7780
// Check for the WebAssembly magic bytes
7881
// See: https://webassembly.github.io/spec/core/binary/modules.html#binary-module
79-
if (strncmp (header, "\0asm", 4))
82+
if (memcmp (header, "\0asm", 4))
8083
return WASM_ENC_INVALID;
8184

8285
/* The next four bytes are the WebAssembly version.

src/libcrun/handlers/handler-utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ typedef enum
3030

3131
int wasm_can_handle_container (libcrun_container_t *container, libcrun_error_t *err);
3232

33-
wasm_encoding_t wasm_interpete_header (const char *header);
33+
wasm_encoding_t wasm_interpret_header (const char *header, const size_t len);
3434

3535
#endif

src/libcrun/handlers/wasmtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ libwasmtime_exec (void *cookie, libcrun_container_t *container arg_unused,
117117
wasm = wasm_bytes;
118118
}
119119

120-
wasm_encoding_t wasm_enc = wasm_interpete_header (wasm.data);
120+
wasm_encoding_t wasm_enc = wasm_interpret_header (wasm.data, wasm.size);
121121
if (wasm_enc == WASM_ENC_INVALID)
122122
error (EXIT_FAILURE, 0, "invalid wasm binary header");
123123

0 commit comments

Comments
 (0)