Skip to content

Commit ebfadf6

Browse files
committed
fix some heap buffer overflows
1 parent 997d8c8 commit ebfadf6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/basic/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ void library_statement(struct basic_ctx* ctx)
292292

293293
/* Load the library file from VFS */
294294
size_t library_len = file_info->size;
295-
char* temp_library = kmalloc(library_len);
295+
char* temp_library = kmalloc(library_len + 1);
296296
if (!temp_library) {
297297
tokenizer_error_print(ctx, "Not enough memory to load library file");
298298
return;
299299
}
300-
char* clean_library = kmalloc(library_len);
300+
char* clean_library = kmalloc(library_len + 1);
301301
if (!clean_library) {
302302
kfree_null(&temp_library);
303303
tokenizer_error_print(ctx, "Not enough memory to load library file");

src/string.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ char* strdup(const char* string)
234234
if (!string) {
235235
return NULL;
236236
}
237-
uint32_t len = strlen(string) + 1;
238-
char* result = kmalloc(len);
239-
strlcpy(result, string, len);
237+
uint32_t len = strlen(string);
238+
char* result = kmalloc(len + 1);
239+
strlcpy(result, string, len + 1);
240240
*(result + len) = 0;
241241
return result;
242242
}
@@ -246,9 +246,9 @@ char* gc_strdup(const char* string)
246246
if (!string) {
247247
return NULL;
248248
}
249-
uint32_t len = strlen(string) + 1;
250-
char* result = kmalloc(len);
251-
strlcpy(result, string, len);
249+
uint32_t len = strlen(string);
250+
char* result = kmalloc(len + 1);
251+
strlcpy(result, string, len + 1);
252252
*(result + len) = 0;
253253

254254
if (gc_list == NULL) {

0 commit comments

Comments
 (0)