1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 06:38:37 -05: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

1
pscp.c
View File

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

View File

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