mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12:48 -05:00
pscp: replace crash with diagnostic on opendir failure.
A user points out that the call to close_directory() in pscp.c's rsource() function should have been inside rather than outside the if statement that checks whether the directory handle is NULL. As a result, any failed attempt to open a directory during a 'pscp -r' recursive upload leads to a null-pointer dereference. Moved the close_directory call to where it should be, and also arranged to print the OS error code if the directory-open fails, by also changing the API of open_directory to return an error string on failure.
This commit is contained in:
@ -266,7 +266,7 @@ struct DirHandle {
|
||||
char *name;
|
||||
};
|
||||
|
||||
DirHandle *open_directory(const char *name)
|
||||
DirHandle *open_directory(const char *name, const char **errmsg)
|
||||
{
|
||||
HANDLE h;
|
||||
WIN32_FIND_DATA fdat;
|
||||
@ -276,8 +276,10 @@ DirHandle *open_directory(const char *name)
|
||||
/* Enumerate files in dir `foo'. */
|
||||
findfile = dupcat(name, "/*", NULL);
|
||||
h = FindFirstFile(findfile, &fdat);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
if (h == INVALID_HANDLE_VALUE) {
|
||||
*errmsg = win_strerror(GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
sfree(findfile);
|
||||
|
||||
ret = snew(DirHandle);
|
||||
|
Reference in New Issue
Block a user