1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

It's not actually legal by the C standard to call qsort with a null

array pointer, _even_ if you're asking it to sort zero elements so
that in principle it should never dereference that pointer. Fix the
four instances in PSCP/PSFTP where this was previously occurring.

[originally from svn r9912]
This commit is contained in:
Simon Tatham 2013-07-11 17:24:39 +00:00
parent 84fed5c620
commit 779466f0b0
2 changed files with 8 additions and 4 deletions

3
pscp.c
View File

@ -765,7 +765,8 @@ void scp_sftp_listdir(char *dirname)
* Now we have our filenames. Sort them by actual file
* name, and then output the longname parts.
*/
qsort(ournames, nnames, sizeof(*ournames), sftp_ls_compare);
if (nnames > 0)
qsort(ournames, nnames, sizeof(*ournames), sftp_ls_compare);
/*
* And print them.

View File

@ -327,7 +327,8 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
* readdirs on the same remote directory return a
* different order.
*/
qsort(ournames, nnames, sizeof(*ournames), sftp_name_compare);
if (nnames > 0)
qsort(ournames, nnames, sizeof(*ournames), sftp_name_compare);
/*
* If we're in restart mode, find the last filename on
@ -570,7 +571,8 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
* same directory, just in case two readdirs on the same
* local directory return a different order.
*/
qsort(ournames, nnames, sizeof(*ournames), bare_name_compare);
if (nnames > 0)
qsort(ournames, nnames, sizeof(*ournames), bare_name_compare);
/*
* If we're in restart mode, find the last filename on this
@ -1093,7 +1095,8 @@ int sftp_cmd_ls(struct sftp_command *cmd)
* Now we have our filenames. Sort them by actual file
* name, and then output the longname parts.
*/
qsort(ournames, nnames, sizeof(*ournames), sftp_name_compare);
if (nnames > 0)
qsort(ournames, nnames, sizeof(*ournames), sftp_name_compare);
/*
* And print them.