From fb73b28d8dd9758d692fc368fd2bb0490b5e3bcc Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 11 Jul 2013 17:24:39 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.tartarus.org/sgt/putty@9912 cda61777-01e9-0310-a592-d414129be87e --- pscp.c | 3 ++- psftp.c | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pscp.c b/pscp.c index 93111d39..0dbe1e34 100644 --- a/pscp.c +++ b/pscp.c @@ -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. diff --git a/psftp.c b/psftp.c index b6a2bb58..65d0dc50 100644 --- a/psftp.c +++ b/psftp.c @@ -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. -- 2.11.0