summaryrefslogtreecommitdiff
path: root/scp.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2009-12-29 21:40:29 +0000
committerColin Watson <cjwatson@debian.org>2009-12-29 21:40:29 +0000
commita25ec0b132c44c9e341e08464ff830de06b81126 (patch)
treee20842d80f9e25cb6cf09525abea63f7bf655dd7 /scp.c
parent1b816ea846aca3ee89e7995373ace609e9518424 (diff)
parent70847d299887abb96f8703ca99db6d817b78960e (diff)
import openssh-4.7p1-gsskex-20070927.patch
Diffstat (limited to 'scp.c')
-rw-r--r--scp.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/scp.c b/scp.c
index a52aaeb12..1765a44e6 100644
--- a/scp.c
+++ b/scp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: scp.c,v 1.156 2007/01/22 13:06:21 djm Exp $ */ 1/* $OpenBSD: scp.c,v 1.160 2007/08/06 19:16:06 sobrado Exp $ */
2/* 2/*
3 * scp - secure remote copy. This is basically patched BSD rcp which 3 * scp - secure remote copy. This is basically patched BSD rcp which
4 * uses ssh to do the data transfer (instead of using rcmd). 4 * uses ssh to do the data transfer (instead of using rcmd).
@@ -96,6 +96,9 @@
96#include <string.h> 96#include <string.h>
97#include <time.h> 97#include <time.h>
98#include <unistd.h> 98#include <unistd.h>
99#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
100#include <vis.h>
101#endif
99 102
100#include "xmalloc.h" 103#include "xmalloc.h"
101#include "atomicio.h" 104#include "atomicio.h"
@@ -582,7 +585,7 @@ source(int argc, char **argv)
582 off_t i, amt, statbytes; 585 off_t i, amt, statbytes;
583 size_t result; 586 size_t result;
584 int fd = -1, haderr, indx; 587 int fd = -1, haderr, indx;
585 char *last, *name, buf[2048]; 588 char *last, *name, buf[2048], encname[MAXPATHLEN];
586 int len; 589 int len;
587 590
588 for (indx = 0; indx < argc; ++indx) { 591 for (indx = 0; indx < argc; ++indx) {
@@ -591,17 +594,17 @@ source(int argc, char **argv)
591 len = strlen(name); 594 len = strlen(name);
592 while (len > 1 && name[len-1] == '/') 595 while (len > 1 && name[len-1] == '/')
593 name[--len] = '\0'; 596 name[--len] = '\0';
597 if ((fd = open(name, O_RDONLY|O_NONBLOCK, 0)) < 0)
598 goto syserr;
594 if (strchr(name, '\n') != NULL) { 599 if (strchr(name, '\n') != NULL) {
595 run_err("%s: skipping, filename contains a newline", 600 strnvis(encname, name, sizeof(encname), VIS_NL);
596 name); 601 name = encname;
597 goto next;
598 } 602 }
599 if ((fd = open(name, O_RDONLY, 0)) < 0)
600 goto syserr;
601 if (fstat(fd, &stb) < 0) { 603 if (fstat(fd, &stb) < 0) {
602syserr: run_err("%s: %s", name, strerror(errno)); 604syserr: run_err("%s: %s", name, strerror(errno));
603 goto next; 605 goto next;
604 } 606 }
607 unset_nonblock(fd);
605 switch (stb.st_mode & S_IFMT) { 608 switch (stb.st_mode & S_IFMT) {
606 case S_IFREG: 609 case S_IFREG:
607 break; 610 break;
@@ -1021,7 +1024,8 @@ bad: run_err("%s: %s", np, strerror(errno));
1021 wrerr = YES; 1024 wrerr = YES;
1022 wrerrno = errno; 1025 wrerrno = errno;
1023 } 1026 }
1024 if (wrerr == NO && ftruncate(ofd, size) != 0) { 1027 if (wrerr == NO && (!exists || S_ISREG(stb.st_mode)) &&
1028 ftruncate(ofd, size) != 0) {
1025 run_err("%s: truncate: %s", np, strerror(errno)); 1029 run_err("%s: truncate: %s", np, strerror(errno));
1026 wrerr = DISPLAYED; 1030 wrerr = DISPLAYED;
1027 } 1031 }
@@ -1116,7 +1120,7 @@ usage(void)
1116 (void) fprintf(stderr, 1120 (void) fprintf(stderr,
1117 "usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n" 1121 "usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n"
1118 " [-l limit] [-o ssh_option] [-P port] [-S program]\n" 1122 " [-l limit] [-o ssh_option] [-P port] [-S program]\n"
1119 " [[user@]host1:]file1 [...] [[user@]host2:]file2\n"); 1123 " [[user@]host1:]file1 ... [[user@]host2:]file2\n");
1120 exit(1); 1124 exit(1);
1121} 1125}
1122 1126