]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
It's not actually legal by the C standard to call qsort with a null
authorSimon Tatham <anakin@pobox.com>
Thu, 11 Jul 2013 17:24:39 +0000 (17:24 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 11 Jul 2013 17:24:39 +0000 (17:24 +0000)
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]

pscp.c
psftp.c

diff --git a/pscp.c b/pscp.c
index 93111d397c3419dbb1bf814060def7e1e44e4742..0dbe1e34e7bad95e4ff71ea3280cc95dffb8c101 100644 (file)
--- 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 b6a2bb5858eeea3812d93790fea5478ac1b990e6..65d0dc50ada89282e6907313514660279dd087cd 100644 (file)
--- 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.