Skip to content

Commit

Permalink
fix SEGV on failed opendir()
Browse files Browse the repository at this point in the history
Reported-by: erikbernsen
Signed-off-by: Ronnie Sahlberg <[email protected]>
  • Loading branch information
sahlberg committed Dec 14, 2024
1 parent badaf2c commit ce73a29
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/libsmb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ free_smb2dir(struct smb2_context *smb2, struct smb2dir *dir)
free(dir->entries);
dir->entries = e;
}
free(dir->cb_data);
free(dir);
}

Expand Down
7 changes: 5 additions & 2 deletions lib/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ static void opendir_cb(struct smb2_context *smb2, int status,
if (cb_data->status == SMB2_STATUS_CANCELLED) {
return;
}

if (status) {
cb_data->status = status;
}
cb_data->is_finished = 1;
cb_data->ptr = command_data;
}
Expand All @@ -195,7 +197,6 @@ struct smb2dir *smb2_opendir(struct smb2_context *smb2, const char *path)
return NULL;
}

/* smb2dir takes wnership of cb_data on success */
if (smb2_opendir_async(smb2, path,
opendir_cb, cb_data) != 0) {
smb2_set_error(smb2, "smb2_opendir_async failed");
Expand All @@ -205,10 +206,12 @@ struct smb2dir *smb2_opendir(struct smb2_context *smb2, const char *path)

if (wait_for_reply(smb2, cb_data) < 0) {
cb_data->status = SMB2_STATUS_CANCELLED;
free(cb_data);
return NULL;
}

ptr = cb_data->ptr;
free(cb_data);
return ptr;
}

Expand Down

0 comments on commit ce73a29

Please sign in to comment.