Use u_char instead of char to avoid buffer overflow error
This commit is contained in:
parent
c37f91d2d2
commit
47406b5def
22
wai.c
22
wai.c
|
@ -54,7 +54,7 @@ struct stack {
|
||||||
|
|
||||||
struct module {
|
struct module {
|
||||||
struct type_t *types;
|
struct type_t *types;
|
||||||
char *funcs[128];
|
u_char *funcs[128];
|
||||||
struct table_t *tables;
|
struct table_t *tables;
|
||||||
struct mem_t *mems;
|
struct mem_t *mems;
|
||||||
struct global_t *globals;
|
struct global_t *globals;
|
||||||
|
@ -63,7 +63,7 @@ struct module {
|
||||||
struct start_t *start;
|
struct start_t *start;
|
||||||
struct import_t *imports;
|
struct import_t *imports;
|
||||||
struct export_t *exports;
|
struct export_t *exports;
|
||||||
char *binary;
|
u_char *binary;
|
||||||
struct stack stack;
|
struct stack stack;
|
||||||
int scope;
|
int scope;
|
||||||
};
|
};
|
||||||
|
@ -111,7 +111,7 @@ double stack_top(struct stack *s) {
|
||||||
return s->items[s->count-1];
|
return s->items[s->count-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_type(char *binary, int len) {
|
int parse_type(u_char *binary, int len) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
enum TYPE param = binary[i];
|
enum TYPE param = binary[i];
|
||||||
printf("type %x\n", param);
|
printf("type %x\n", param);
|
||||||
|
@ -131,11 +131,11 @@ int parse_type(char *binary, int len) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_function(struct module *module, char *binary, double param, int len);
|
int parse_function(struct module *module, u_char *binary, double param, int len);
|
||||||
int parse_instruction(struct module *module, char *binary, double param, int len) {
|
int parse_instruction(struct module *module, u_char *binary, double param, int len) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
enum INSTRUCTION instr = (u_char) binary[i];
|
enum INSTRUCTION instr = (u_char) binary[i];
|
||||||
char *instr_addr = &binary[i];
|
u_char *instr_addr = &binary[i];
|
||||||
incr(i, len);
|
incr(i, len);
|
||||||
|
|
||||||
switch (instr) {
|
switch (instr) {
|
||||||
|
@ -205,7 +205,7 @@ int parse_instruction(struct module *module, char *binary, double param, int len
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_function(struct module *module, char *binary, double param, int len) {
|
int parse_function(struct module *module, u_char *binary, double param, int len) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int body_size = binary[i];
|
int body_size = binary[i];
|
||||||
incr(i, len);
|
incr(i, len);
|
||||||
|
@ -219,7 +219,7 @@ int parse_function(struct module *module, char *binary, double param, int len) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_section(struct module *module, char *binary, int len) {
|
int parse_section(struct module *module, u_char *binary, int len) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
enum section type = binary[i];
|
enum section type = binary[i];
|
||||||
incr(i, len);
|
incr(i, len);
|
||||||
|
@ -314,9 +314,9 @@ int parse_section(struct module *module, char *binary, int len) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_module(char *binary, size_t len) {
|
int parse_module(u_char *binary, size_t len) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *magic = "\0asm";
|
u_char *magic = "\0asm";
|
||||||
while (i < 4) {
|
while (i < 4) {
|
||||||
if (binary[i] != magic[i]) {
|
if (binary[i] != magic[i]) {
|
||||||
fprintf(stderr, "no wasm magic\n");
|
fprintf(stderr, "no wasm magic\n");
|
||||||
|
@ -355,7 +355,7 @@ int main(int argc, char **argv) {
|
||||||
stat(argv[1], &st);
|
stat(argv[1], &st);
|
||||||
printf("size: %ld\n", st.st_size);
|
printf("size: %ld\n", st.st_size);
|
||||||
|
|
||||||
char *binary = malloc(st.st_size);
|
unsigned char *binary = malloc(st.st_size);
|
||||||
fread(binary, st.st_size, st.st_size, file);
|
fread(binary, st.st_size, st.st_size, file);
|
||||||
|
|
||||||
if (parse_module(binary, st.st_size) == -1) {
|
if (parse_module(binary, st.st_size) == -1) {
|
||||||
|
|
Loading…
Reference in a new issue