If file functions are called with NULL arg silently return.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-12-24 01:39:26 +01:00
parent a8fe504d14
commit 36b2924036
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
2 changed files with 6 additions and 0 deletions

View file

@ -284,6 +284,8 @@ file_t *search_dynamic_file(uint16_t fid) {
}
int delete_dynamic_file(file_t *f) {
if (f == NULL)
return NULL;
for (int i = 0; i < dynamic_files; i++) {
if (dynamic_file[i].fid == f->fid) {
for (int j = i+1; j < dynamic_files; j++)
@ -439,6 +441,8 @@ bool file_has_data(file_t *f) {
}
int delete_file(file_t *ef) {
if (ef == NULL)
return CCID_OK;
meta_delete(ef->fid);
if (flash_clear_file(ef) != CCID_OK)
return CCID_EXEC_ERROR;

View file

@ -95,6 +95,8 @@ uintptr_t allocate_free_addr(uint16_t size, bool persistent) {
}
int flash_clear_file(file_t *file) {
if (file == NULL)
return CCID_OK;
uintptr_t base_addr = (uintptr_t)(file->data-sizeof(uintptr_t)-sizeof(uint16_t)-sizeof(uintptr_t));
uintptr_t prev_addr = flash_read_uintptr(base_addr+sizeof(uintptr_t));
uintptr_t next_addr = flash_read_uintptr(base_addr);