-
Notifications
You must be signed in to change notification settings - Fork 29
acdb: Fix stale delta file handle reuse #114
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: master
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 |
|---|---|---|
|
|
@@ -327,8 +327,12 @@ int32_t AcdbDeltaDataCmdSave(void) | |
|
|
||
| fhandle = &db_info->file_handle; | ||
|
|
||
| /* Close and delete old delta file */ | ||
| ar_fclose(*fhandle); | ||
| //Close and delete old delta file | ||
| if (*fhandle != NULL) | ||
| { | ||
| ar_fclose(*fhandle); | ||
| *fhandle = NULL; | ||
| } | ||
|
|
||
| status = ar_fdelete(db_info->delta_file_path.path); | ||
| if (AR_FAILED(status)) | ||
|
Comment on lines
+333
to
338
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. [FUNCTIONALITY] Potential double-free risk in error path of AcdbDeltaDataCmdSave() - Medium Severity In Later in the function, if any subsequent operation fails and execution reaches the This could lead to inconsistent state where:
This inconsistency could cause issues in subsequent operations that check these flags. Fixed Code Snippetstatus = ar_fdelete(db_info->delta_file_path.path);
if (AR_FAILED(status))
{
ACDB_ERR("Error[%d]: Failed to delete delta file", status);
db_info->exists = FALSE; // Mark as non-existent since we can't delete it
db_info->file_size = 0;
goto end;
} |
||
|
|
@@ -403,7 +407,6 @@ int32_t AcdbDeltaDataCmdSave(void) | |
| end: | ||
| AcdbListClear(p_map_list); | ||
| p_map_list = NULL; | ||
|
|
||
| return status; | ||
| } | ||
| int32_t AcdbDeltaInitHeap(acdb_context_handle_t *handle) | ||
|
|
@@ -554,11 +557,15 @@ int32_t AcdbDeltaDeleteFile(uint32_t database_index) | |
| &file_name_info, sizeof(file_name_info)); | ||
|
|
||
| //Close and delete old delta file | ||
| status = ar_fclose(*fhandle); | ||
| if (AR_EOK != status) | ||
| if (*fhandle != NULL) | ||
| { | ||
| ACDB_ERR("Error[%d]: Failed to close delta file", status); | ||
| return status; | ||
| status = ar_fclose(*fhandle); | ||
| *fhandle = NULL; | ||
| if (AR_EOK != status) | ||
| { | ||
| ACDB_ERR("Error[%d]: Failed to close delta file", status); | ||
| return status; | ||
| } | ||
| } | ||
|
|
||
| status = AcdbInitUtilDeleteDeltaFileData( | ||
|
|
@@ -600,12 +607,16 @@ int32_t AcdbDeltaDataSwapDelta(AcdbDeltaDataSwapInfo *swap_info) | |
| db_info = ACDB_DFM_DB_INFO_AT_INDEX(swap_info->file_index); | ||
|
|
||
| /* Close the previous delta file and open/create the new file */ | ||
| status = ar_fclose(db_info->file_handle); | ||
| if (AR_FAILED(status)) | ||
| if (db_info->file_handle != NULL) | ||
| { | ||
| ACDB_ERR("Error[%d]: Failed to close %s ", status, | ||
| db_info->delta_file_path.path); | ||
| return status; | ||
| status = ar_fclose(db_info->file_handle); | ||
| db_info->file_handle = NULL; | ||
| if (AR_FAILED(status)) | ||
| { | ||
| ACDB_ERR("Error[%d]: Failed to close %s ", status, | ||
| db_info->delta_file_path.path); | ||
| return status; | ||
| } | ||
| } | ||
|
|
||
| status = acdb_file_man_ioctl(ACDB_FILE_MAN_GET_FILE_NAME, | ||
|
|
||
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.
[ERROR HANDLING] Missing error handling for ar_fclose() in AcdbDeltaDataCmdSave() - High Severity
In the
AcdbDeltaDataCmdSave()function at lines 331-335, the code callsar_fclose(*fhandle)but does not check the return status. This is inconsistent with the other two modified functions (AcdbDeltaDeleteFile()andAcdbDeltaDataSwapDelta()) which both check the return status and handle errors appropriately.If
ar_fclose()fails, the function continues execution and attempts to delete the file, which could lead to:This is particularly critical since this function is responsible for persisting delta data, and a failed close operation could result in data loss.
Fixed Code Snippet