Skip to content

Commit

Permalink
Fix an export name check exception
Browse files Browse the repository at this point in the history
Use a new WASMName to represent *name* of import and export
  • Loading branch information
lum1n0us committed Nov 23, 2023
1 parent 9ad4229 commit 4d8f1b6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
12 changes: 7 additions & 5 deletions core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "bh_platform.h"
#include "bh_hashmap.h"
#include "bh_assert.h"
#include "wasm_name.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -88,6 +89,7 @@ extern "C" {
typedef struct WASMModule WASMModule;
typedef struct WASMFunction WASMFunction;
typedef struct WASMGlobal WASMGlobal;
typedef struct WASMName WASMName;

typedef union V128 {
int8 i8x16[16];
Expand Down Expand Up @@ -224,11 +226,11 @@ typedef struct WASMImport {
WASMTableImport table;
WASMMemoryImport memory;
WASMGlobalImport global;
struct {
char *module_name;
char *field_name;
} names;
} u;
struct {
const WASMName *module_name;
const WASMName *field_name;
} names;
} WASMImport;

struct WASMFunction {
Expand Down Expand Up @@ -301,7 +303,7 @@ struct WASMGlobal {
};

typedef struct WASMExport {
char *name;
const WASMName *name;
uint8 kind;
uint32 index;
} WASMExport;
Expand Down
4 changes: 3 additions & 1 deletion core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,9 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,

for (j = 0; j < i; j++) {
name = module->exports[j].name;
if (strlen(name) == str_len && memcmp(name, p, str_len) == 0) {
/* If str_len is zero, the return value of memcmp is zero */
if (str_len && strlen(name) == str_len
&& memcmp(name, p, str_len) == 0) {
set_error_buf(error_buf, error_buf_size,
"duplicate export name");
return false;
Expand Down
Empty file.
26 changes: 26 additions & 0 deletions core/iwasm/interpreter/wasm_name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#ifndef _WASM_NAME_H_
#define _WASM_NAME_H_

#include "bh_platform.h"
#include "bh_assert.h"

typedef struct WASMName {
const char *chars;
uint32 length;
} WASMName;

WASMName *
wasm_name_new(const char *chars, uint32 length);

void
wasm_name_delete(WASMName *name);

int
wasm_name_compare(const WASMName *name1, const WASMName *name2);

#endif /* end of _WASM_NAME_H_ */

0 comments on commit 4d8f1b6

Please sign in to comment.