fix buffer overrun and uninitialized variable

This commit is contained in:
IoIxD 2026-01-19 22:06:57 -07:00
commit efeeb73ef5
3 changed files with 11 additions and 8 deletions

View file

@ -107,6 +107,9 @@ void *msh_allocate(SIZE_TYPE size) {
};
void msh_deallocate(void *ptr) {
if (ptr == 0) {
return;
}
msh_linux_block *block = get_metadata_block(ptr);
block->free = 1;
if (block->prev && block->prev->free) {

View file

@ -5,9 +5,9 @@ msh_linux_env_item *env_items = 0;
msh_linux_env_item *env_item_tail = 0;
void msh_linux_env_map_init() {
msh_file *env_file;
SIZE_TYPE cur;
char *file_buf;
msh_file *env_file = 0;
SIZE_TYPE cur = 0;
char *file_buf = 0;
char ch = 1;
int counter = 0, i = 0;

View file

@ -33,7 +33,6 @@ int msh_execute(char *cmd, char **args) {
return 0;
}
SIZE_TYPE fork = (SIZE_TYPE)SYSCALL(fork, 0);
// int fork = 0;
if (fork == 0) {
char **env_translated = 0;
@ -52,7 +51,8 @@ int msh_execute(char *cmd, char **args) {
int n = 0;
char *entry =
msh_allocate(item_list->key_len + item_list->value_len + 2);
msh_str_copy_strs(entry, item_list->key, "=", item_list->value, "\0");
msh_str_copy_strs(entry, item_list->key, "=", item_list->value, "\0",
0);
env_translated[i++] = entry;
}
item_list = item_list->next;
@ -99,10 +99,10 @@ msh_file *msh_file_open(const char *file) {
return f;
};
void msh_file_close(msh_file *file) {
SYSCALL(close, file->fd);
void msh_file_close(msh_file *file) {
SYSCALL(close, file->fd);
msh_deallocate(file);
msh_deallocate(file);
};
void msh_file_read(msh_file *file, char *ptr, SIZE_TYPE n) {