-
Notifications
You must be signed in to change notification settings - Fork 103
Memory-safety fixes: uninitialized reads and a realloc leak #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4404,7 +4404,9 @@ void ltfs_enable_livelink_mode(struct ltfs_volume *vol) | |
| */ | ||
| int ltfs_profiler_set(uint64_t source, struct ltfs_volume *vol) | ||
| { | ||
| int ret, ret_save = 0; | ||
| /* ret stays unset if neither the iosched nor device handle is present; | ||
| * the final "if (!ret && ret_save)" would then read garbage. */ | ||
|
Comment on lines
+4407
to
+4408
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is out of scope for documentation, there's no need to over explain the initialization of the variable. Was this AI generated? |
||
| int ret = 0, ret_save = 0; | ||
|
|
||
| if (vol->iosched_handle) { | ||
| if (source & PROF_IOSCHED) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,10 +197,14 @@ int pathname_prepare_caseless(const char *name, UChar **new_name, bool use_nfc) | |
| /* Convert to NFD if needed, then case fold the name. */ | ||
| if (need_initial_nfd) { | ||
| ret = _pathname_normalize_nfd_icu(icu_name, &icu_nfd); | ||
| if (icu_name != icu_nfd) | ||
| if (ret < 0) { | ||
| /* icu_nfd is unset on error; free the input and bail before | ||
| * comparing the (garbage) output pointer. */ | ||
|
Comment on lines
+201
to
+202
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto about the comment. |
||
| free(icu_name); | ||
| if (ret < 0) | ||
| return ret; | ||
| } | ||
| if (icu_name != icu_nfd) | ||
| free(icu_name); | ||
| ret = _pathname_foldcase_icu(icu_nfd, &icu_fold); | ||
| free(icu_nfd); | ||
| if (ret < 0) | ||
|
|
@@ -217,10 +221,14 @@ int pathname_prepare_caseless(const char *name, UChar **new_name, bool use_nfc) | |
| ret = _pathname_normalize_nfc_icu(icu_fold, new_name); | ||
| else | ||
| ret = _pathname_normalize_nfd_icu(icu_fold, new_name); | ||
| if (icu_fold != *new_name) | ||
| if (ret < 0) { | ||
| /* *new_name is unset on error; free the input and bail before | ||
| * comparing the (garbage) output pointer. */ | ||
|
Comment on lines
+225
to
+226
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto about the comment. |
||
| free(icu_fold); | ||
| if (ret < 0) | ||
| return ret; | ||
| } | ||
| if (icu_fold != *new_name) | ||
| free(icu_fold); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
@@ -475,10 +483,12 @@ int _pathname_format_icu(const char *src, char **dest, bool validate, bool allow | |
|
|
||
| /* normalize */ | ||
| ret = _pathname_normalize_nfc_icu(utf16_name, &utf16_name_norm); | ||
| if (utf16_name != utf16_name_norm) | ||
| if (ret < 0) { | ||
| free(utf16_name); | ||
| if (ret < 0) | ||
| return ret; | ||
| } | ||
| if (utf16_name != utf16_name_norm) | ||
| free(utf16_name); | ||
|
|
||
| /* convert to UTF-8 */ | ||
| ret = _pathname_utf16_to_utf8_icu(utf16_name_norm, dest); | ||
|
|
@@ -534,10 +544,12 @@ int _pathname_normalize_utf8_nfd_icu(const char *src, char **dest) | |
| return ret; | ||
|
|
||
| ret = _pathname_normalize_nfd_icu(icu_str, &icu_str_norm); | ||
| if (icu_str != icu_str_norm) | ||
| if (ret < 0) { | ||
| free(icu_str); | ||
| if (ret < 0) | ||
| return ret; | ||
| } | ||
| if (icu_str != icu_str_norm) | ||
| free(icu_str); | ||
|
|
||
| ret = _pathname_utf16_to_utf8_icu(icu_str_norm, dest); | ||
| free(icu_str_norm); | ||
|
|
@@ -602,10 +614,12 @@ int _pathname_normalize_utf8_icu(const char *src, char **dest) | |
| return ret; | ||
|
|
||
| ret = _pathname_normalize_nfc_icu(icu_str, &icu_str_norm); | ||
| if (icu_str != icu_str_norm) | ||
| if (ret < 0) { | ||
| free(icu_str); | ||
| if (ret < 0) | ||
| return ret; | ||
| } | ||
| if (icu_str != icu_str_norm) | ||
| free(icu_str); | ||
|
|
||
| ret = _pathname_utf16_to_utf8_icu(icu_str_norm, dest); | ||
| free(icu_str_norm); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,7 +373,10 @@ int tape_load_tape(struct device_data *dev, void * const kmi_handle, bool force) | |
| int ret; | ||
| struct tc_drive_param param; | ||
| struct tc_remaining_cap cap; | ||
| uint16_t pews; | ||
| /* tape_get_pews leaves this unset when it returns -LTFS_UNSUPPORTED, | ||
| * which the caller treats as non-fatal and then reads pews; default to 0 | ||
| * so the fallback (pews + 10) is deterministic. */ | ||
|
Comment on lines
+376
to
+378
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto about the comment. |
||
| uint16_t pews = 0; | ||
|
|
||
| CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); | ||
| CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,7 +311,13 @@ static int _get_dump(struct sg_data *priv, char *fname) | |
| } | ||
|
|
||
| /* Get buffer capacity */ | ||
| _cdb_read_buffer(priv, buf_id, cap_buf, 0, sizeof(cap_buf), 0x03); | ||
| ret = _cdb_read_buffer(priv, buf_id, cap_buf, 0, sizeof(cap_buf), 0x03); | ||
| if (ret < 0) { | ||
| /* cap_buf is indeterminate on failure; do not derive a transfer | ||
| * length from it. */ | ||
|
Comment on lines
+316
to
+317
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto about the comment. |
||
| free(dump_buf); | ||
| return ret; | ||
| } | ||
| data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int)cap_buf[3]; | ||
|
|
||
| /* Open dump file for write only*/ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems to add more unnecessary complexity and repeated code. Maybe adding the brackets for clarity can be a good change. The added free on the original error path should be enough.