]> andersk Git - openssh.git/blobdiff - sftp.c
- ray@cvs.openbsd.org 2006/11/23 01:35:11
[openssh.git] / sftp.c
diff --git a/sftp.c b/sftp.c
index 868794a76ad9d2d38c0793e1358fa8c2b06144c4..990b0cbbd0ff2b8f845382c6357f1f809f9a4507 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: sftp.c,v 1.94 2006/11/23 01:35:11 ray Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
 #include "includes.h"
 
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
-#include <sys/ioctl.h>
+#include <sys/param.h>
+#include <sys/socket.h>
 #include <sys/wait.h>
 
+#include <errno.h>
+
 #ifdef HAVE_PATHS_H
 # include <paths.h>
 #endif
 typedef void EditLine;
 #endif
 #include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdarg.h>
 
-#include "buffer.h"
 #include "xmalloc.h"
 #include "log.h"
 #include "pathnames.h"
 #include "misc.h"
 
 #include "sftp.h"
+#include "buffer.h"
 #include "sftp-common.h"
 #include "sftp-client.h"
 
@@ -288,11 +298,11 @@ static char *
 path_append(char *p1, char *p2)
 {
        char *ret;
-       int len = strlen(p1) + strlen(p2) + 2;
+       size_t len = strlen(p1) + strlen(p2) + 2;
 
        ret = xmalloc(len);
        strlcpy(ret, p1, len);
-       if (p1[strlen(p1) - 1] != '/')
+       if (p1[0] != '\0' && p1[strlen(p1) - 1] != '/')
                strlcat(ret, "/", len);
        strlcat(ret, p2, len);
 
@@ -483,7 +493,7 @@ is_dir(char *path)
        if (stat(path, &sb) == -1)
                return(0);
 
-       return(sb.st_mode & S_IFDIR);
+       return(S_ISDIR(sb.st_mode));
 }
 
 static int
@@ -507,7 +517,7 @@ remote_is_dir(struct sftp_conn *conn, char *path)
                return(0);
        if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS))
                return(0);
-       return(a->perm & S_IFDIR);
+       return(S_ISDIR(a->perm));
 }
 
 static int
@@ -547,6 +557,7 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag)
 
                if (g.gl_matchc == 1 && dst) {
                        /* If directory specified, append filename */
+                       xfree(tmp);
                        if (is_dir(dst)) {
                                if (infer_path(g.gl_pathv[0], &tmp)) {
                                        err = 1;
@@ -571,8 +582,6 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag)
 
 out:
        xfree(abs_src);
-       if (abs_dst)
-               xfree(abs_dst);
        globfree(&g);
        return(err);
 }
@@ -968,6 +977,7 @@ parse_args(const char **cpp, int *pflag, int *lflag, int *iflag,
        case I_CHOWN:
        case I_CHGRP:
                /* Get numeric arg (mandatory) */
+               errno = 0;
                l = strtol(cp, &cp2, base);
                if (cp2 == cp || ((l == LONG_MIN || l == LONG_MAX) &&
                    errno == ERANGE) || l < 0) {
@@ -1467,7 +1477,7 @@ main(int argc, char **argv)
        __progname = ssh_get_progname(argv[0]);
        memset(&args, '\0', sizeof(args));
        args.list = NULL;
-       addargs(&args, ssh_program);
+       addargs(&args, "%s", ssh_program);
        addargs(&args, "-oForwardX11 no");
        addargs(&args, "-oForwardAgent no");
        addargs(&args, "-oPermitLocalCommand no");
This page took 0.036708 seconds and 4 git commands to generate.