-
Notifications
You must be signed in to change notification settings - Fork 87
Fix: strdup memory check #523
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: v2.4-stable
Are you sure you want to change the base?
Changes from all commits
7a3d4ee
1908efa
46b5724
7ea045c
0bec91b
5bc15ee
7348d2f
a2d4a0a
2ed7743
e94c944
83ea0f2
3c37ee0
f0ae574
b95a9c5
559fa1e
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
** OO_Copyright_BEGIN | ||
** | ||
** | ||
** Copyright 2010, 2020 IBM Corp. All rights reserved. | ||
** Copyright 2010, 2025 IBM Corp. All rights reserved. | ||
** | ||
** Redistribution and use in source and binary forms, with or without | ||
** modification, are permitted provided that the following conditions | ||
|
@@ -288,27 +288,38 @@ int index_criteria_parse_name(const char *criteria, size_t len, struct index_cri | |
/* Assign rules to the glob_patterns[] array */ | ||
rule = rule+5; | ||
for (delim = rule; *delim; delim++) { | ||
bool do_delim_assign = false; | ||
bool do_rule_add = false; | ||
if (*delim == ':') { | ||
*delim = '\0'; | ||
rule_ptr->percent_encode = fs_is_percent_encode_required(rule); | ||
rule_ptr->name = strdup(rule); | ||
rule_ptr++; | ||
rule = delim+1; | ||
} else if (*delim == '/') { | ||
*delim = '\0'; | ||
rule_ptr->percent_encode = fs_is_percent_encode_required(rule); | ||
rule_ptr->name = strdup(rule); | ||
rule_ptr++; | ||
} else if (*(delim+1) == '\0') { | ||
rule_ptr->percent_encode = fs_is_percent_encode_required(rule); | ||
rule_ptr->name = strdup(rule); | ||
rule_ptr++; | ||
do_delim_assign = true; | ||
do_rule_add = true; | ||
} | ||
else if (*delim == '/') { | ||
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. Please follow the convention. You must not break a line before It looks there are multiple points that is same style. Please correct all of them. 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. Will check them. |
||
do_delim_assign = true; | ||
} | ||
else if (! (*(delim+1) == '\0')) { | ||
continue; | ||
} | ||
if (do_delim_assign) *delim = '\0'; | ||
rule_ptr->percent_encode = fs_is_percent_encode_required(rule); | ||
rule_ptr->name = strdup(rule); | ||
if (! rule_ptr->name) { | ||
ltfsmsg(LTFS_ERR, 10001E, "index_criteria_parse_name: rule assign"); | ||
free(rule_ptr->name); | ||
return -LTFS_NO_MEMORY; | ||
} | ||
rule_ptr++; | ||
if (do_rule_add) rule = delim+1; | ||
} | ||
|
||
if (ic->glob_patterns == rule_ptr) { | ||
rule_ptr->percent_encode = fs_is_percent_encode_required(rule); | ||
rule_ptr->name = strdup(rule); | ||
if (! rule_ptr->name) { | ||
ltfsmsg(LTFS_ERR, 10001E, "index_criteria_parse_name: glob_patterns assign"); | ||
free(rule_ptr->name); | ||
return -EDEV_NO_MEMORY; | ||
XV02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
/* Validate rules */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1659,7 +1659,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec | |
(unsigned long long)volume_change_ref); | ||
|
||
/* Index of IP could be corrupted. So set skip flag to true */ | ||
ret = _ltfs_search_index_wp(recover_symlink, true, &seekpos, vol); | ||
ret = _ltfs_search_index_wp(recover_symlink, false, &seekpos, vol); | ||
XV02 marked this conversation as resolved.
Show resolved
Hide resolved
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. Why this line is changed? It looks you ruined the fix made before. 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. It looks a change from somewhere else got into the PR, fixing it, thanks for the catch. |
||
if (ret < 0) | ||
goto out_unlock; | ||
|
||
|
@@ -1669,8 +1669,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec | |
seekpos.block = vol->dp_coh.set_id; | ||
} | ||
} else { | ||
if (vol->ip_coh.count > vol->dp_coh.count && vollock != PWE_MAM_DP && vollock != PWE_MAM) { | ||
/* | ||
if (vol->ip_coh.count > vol->dp_coh.count && vollock != PWE_MAM_DP && vollock != PWE_MAM) { /* | ||
* The index on IP is newer but MAM shows write perm doesn't happen in DP. | ||
* LTFS already have written an index on DP when it is writing an index on IP, | ||
* so this condition wouldn't happen logically. | ||
|
@@ -1688,13 +1687,8 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec | |
(unsigned long long)vol->dp_coh.volume_change_ref, | ||
(unsigned long long)volume_change_ref); | ||
|
||
if (vollock == PWE_MAM_BOTH) { | ||
/* Index of IP could be corrupted (because of double write perm). So set skip flag to true */ | ||
ret = _ltfs_search_index_wp(recover_symlink, true, &seekpos, vol); | ||
} else { | ||
/* Index of DP could be corrupted. So set skip flag to false */ | ||
ret = _ltfs_search_index_wp(recover_symlink, false, &seekpos, vol); | ||
} | ||
/* Index of IP could be corrupted. So set skip flag */ | ||
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. Why this part is changed? It looks you ruined the fix made before. 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. It looks a change from somewhere else got into the PR, fixing it, thanks for the catch. |
||
ret = _ltfs_search_index_wp(recover_symlink, true, &seekpos, vol); | ||
if (ret < 0) | ||
goto out_unlock; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
** OO_Copyright_BEGIN | ||
** | ||
** | ||
** Copyright 2010, 2021 IBM Corp. All rights reserved. | ||
** Copyright 2010, 2025 IBM Corp. All rights reserved. | ||
** | ||
** Redistribution and use in source and binary forms, with or without | ||
** modification, are permitted provided that the following conditions | ||
|
@@ -1912,7 +1912,12 @@ int ltfs_fsops_symlink_path(const char* to, const char* from, ltfs_file_id *id, | |
|
||
id->uid = d->uid; | ||
id->ino = d->ino; | ||
// TODO: Check if the return error is needed or can be skipped. | ||
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. Please avoid adding technical debt hehe, did you just forget to erase this TODO? Or you did not manage to check it? 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. Please use C++ style command only for comment out. 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. I will do the testing so I can completely remove them, thanks. |
||
d->target.name = strdup(to); | ||
if (! d->target.name) { | ||
ltfsmsg(LTFS_ERR, 10001E, "ltfs_fsops_symlink_path: d target name"); | ||
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. You need to remove the node created by 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. Hi @piste-jp using the following code is enough to remove the node, or do I need to do something else? Thanks ret2 = ltfs_fsops_close(d, true, true, use_iosche, vol);
if ( ret==0 && ret2<0 ) {
ret = ret2;
} |
||
return -LTFS_NO_MEMORY; | ||
} | ||
d->target.percent_encode = fs_is_percent_encode_required(to); | ||
d->isslink = true; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
** OO_Copyright_BEGIN | ||
** | ||
** | ||
** Copyright 2010, 2020 IBM Corp. All rights reserved. | ||
** Copyright 2010, 2025 IBM Corp. All rights reserved. | ||
** | ||
** Redistribution and use in source and binary forms, with or without | ||
** modification, are permitted provided that the following conditions | ||
|
@@ -1313,6 +1313,10 @@ int ltfs_split_symlink( struct ltfs_volume *vol ) | |
} | ||
ret = ltfs_fsops_close( workd, true, true, use_iosche, vol); | ||
path=strdup(lfdir); | ||
if (! path) { | ||
ltfsmsg(LTFS_ERR, 10001E, "ltfs_split_symlink: path assign"); | ||
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. You need to remove the node created by tfs_fsops_create() in line 1303 at least. 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. Hi @piste-jp the node is closed just above those lines, in 1314, is something else needed? Thanks a lot |
||
return -LTFS_NO_MEMORY; | ||
} | ||
|
||
/* loop for conflicted files */ | ||
for( i=0; i<(vol->index->symerr_count); i++ ){ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
** OO_Copyright_BEGIN | ||
** | ||
** | ||
** Copyright 2010, 2020 IBM Corp. All rights reserved. | ||
** Copyright 2010, 2025 IBM Corp. All rights reserved. | ||
** | ||
** Redistribution and use in source and binary forms, with or without | ||
** modification, are permitted provided that the following conditions | ||
|
@@ -489,6 +489,11 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id, | |
vsprintf(msg_buf, output_buf, argp); | ||
va_end(argp); | ||
*msg_out = strdup(msg_buf); | ||
// TODO: Check if the return -1 is needed, or the program can just continue | ||
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. Same as before, please do not add more technical debt, I cannot approve a PR that has not been properly tested 😅 |
||
if (!(*msg_out)) { | ||
ltfsmsg(LTFS_ERR, 10001E, "ltfsmsg_internal: msg_out assign"); | ||
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. It is a terrible idea to use 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. Hi @piste-jp your insight would be really helpful here, it is crucial to stop the process and return an error in this section (For example using the goto internal_error) or just printing a message using the fprintf or syslog functions? Thanks |
||
return -1; | ||
} | ||
} | ||
|
||
#ifdef ENABLE_SNMP | ||
|
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. Did you really test this code? This code is only compiled under FreeBSD. 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. Working on it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
** OS_Copyright_BEGIN | ||
** | ||
** | ||
** Copyright 2010, 2018 IBM Corp. All rights reserved. | ||
** Copyright 2010, 2025 IBM Corp. All rights reserved. | ||
** Copyright (c) 2013-2018 Spectra Logic Corporation. All rights reserved. | ||
** | ||
** Redistribution and use in source and binary forms, with or without | ||
|
@@ -189,6 +189,10 @@ int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data | |
|
||
if (msg) { | ||
*msg = strdup("No Sense Information"); | ||
if (! (*msg)) { | ||
ltfsmsg(LTFS_ERR, 10001E, "camtape_ioctlrc2err: msg assign"); | ||
// TODO: Check if error return is needed | ||
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. Same as before |
||
} | ||
} | ||
rc = -EDEV_NO_SENSE; | ||
} else { | ||
|
@@ -217,6 +221,10 @@ int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data | |
ltfsmsg(LTFS_INFO, 31212I, rc_sense); | ||
if (msg) | ||
*msg = strdup("Cannot get sense information"); | ||
if (! (*msg)) { | ||
ltfsmsg(LTFS_ERR, 10001E, "camtape_ioctlrc2err: msg assign"); | ||
// TODO: Check if error return is needed | ||
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. Same as before |
||
} | ||
|
||
rc = -EDEV_CANNOT_GET_SENSE; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.