Add buffer overflow check in mz_os_read_symlink function #944

This commit is contained in:
Nathan Moinvaziri 2026-01-27 09:27:44 -08:00
parent 0fa77a3861
commit 9963dd30c5
No known key found for this signature in database
2 changed files with 6 additions and 2 deletions

View file

@ -329,8 +329,10 @@ int32_t mz_dir_has_unsafe_symlink(const char *path, const char *base_path) {
/* Check if this existing path component is a symlink */
if (mz_os_is_symlink(check_path) != MZ_OK)
continue;
if (mz_os_read_symlink(check_path, symlink_target, (int32_t)(path_len + 1)) != MZ_OK)
continue;
if (mz_os_read_symlink(check_path, symlink_target, (int32_t)(path_len + 1)) != MZ_OK) {
err = MZ_EXIST_ERROR;
break;
}
/* Absolute symlink targets are not allowed */
if (mz_os_is_dir_separator(symlink_target[0])) {