summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--sftp-client.c11
-rw-r--r--sftp-int.c24
3 files changed, 36 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index bbd769ebd..36d5d2ca0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,10 @@
14 [sftp-int.c] 14 [sftp-int.c]
15 make cmds[] array static to avoid conflict with BSDI libc. 15 make cmds[] array static to avoid conflict with BSDI libc.
16 mindrot bug #466. Fix from mdev@idg.nl; ok markus@ 16 mindrot bug #466. Fix from mdev@idg.nl; ok markus@
17 - djm@cvs.openbsd.org 2003/01/14 10:58:00
18 [sftp-client.c sftp-int.c]
19 Don't try to upload or download non-regular files. Report from
20 apoloval@pantuflo.escet.urjc.es; ok markus@
17 21
1820030113 2220030113
19 - (djm) Rework openbsd-compat/setproctitle.c a bit: move emulation type 23 - (djm) Rework openbsd-compat/setproctitle.c a bit: move emulation type
@@ -1017,4 +1021,4 @@
1017 save auth method before monitor_reset_key_state(); bugzilla bug #284; 1021 save auth method before monitor_reset_key_state(); bugzilla bug #284;
1018 ok provos@ 1022 ok provos@
1019 1023
1020$Id: ChangeLog,v 1.2571 2003/01/14 11:24:19 djm Exp $ 1024$Id: ChangeLog,v 1.2572 2003/01/14 11:24:47 djm Exp $
diff --git a/sftp-client.c b/sftp-client.c
index 3fac22bee..8c12dae11 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -28,7 +28,7 @@
28/* XXX: copy between two remote sites */ 28/* XXX: copy between two remote sites */
29 29
30#include "includes.h" 30#include "includes.h"
31RCSID("$OpenBSD: sftp-client.c,v 1.40 2003/01/10 08:48:15 djm Exp $"); 31RCSID("$OpenBSD: sftp-client.c,v 1.41 2003/01/14 10:58:00 djm Exp $");
32 32
33#include "openbsd-compat/sys-queue.h" 33#include "openbsd-compat/sys-queue.h"
34 34
@@ -767,8 +767,8 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
767 mode = 0666; 767 mode = 0666;
768 768
769 if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && 769 if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) &&
770 (a->perm & S_IFDIR)) { 770 (!S_ISREG(a->perm))) {
771 error("Cannot download a directory: %s", remote_path); 771 error("Cannot download non-regular file: %s", remote_path);
772 return(-1); 772 return(-1);
773 } 773 }
774 774
@@ -1002,6 +1002,11 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1002 close(local_fd); 1002 close(local_fd);
1003 return(-1); 1003 return(-1);
1004 } 1004 }
1005 if (!S_ISREG(sb.st_mode)) {
1006 error("%s is not a regular file", local_path);
1007 close(local_fd);
1008 return(-1);
1009 }
1005 stat_to_attrib(&sb, &a); 1010 stat_to_attrib(&sb, &a);
1006 1011
1007 a.flags &= ~SSH2_FILEXFER_ATTR_SIZE; 1012 a.flags &= ~SSH2_FILEXFER_ATTR_SIZE;
diff --git a/sftp-int.c b/sftp-int.c
index 3438fdeb0..42040f5bd 100644
--- a/sftp-int.c
+++ b/sftp-int.c
@@ -25,7 +25,7 @@
25/* XXX: recursive operations */ 25/* XXX: recursive operations */
26 26
27#include "includes.h" 27#include "includes.h"
28RCSID("$OpenBSD: sftp-int.c,v 1.54 2003/01/13 11:04:04 djm Exp $"); 28RCSID("$OpenBSD: sftp-int.c,v 1.55 2003/01/14 10:58:00 djm Exp $");
29 29
30#include "buffer.h" 30#include "buffer.h"
31#include "xmalloc.h" 31#include "xmalloc.h"
@@ -381,6 +381,17 @@ is_dir(char *path)
381} 381}
382 382
383static int 383static int
384is_reg(char *path)
385{
386 struct stat sb;
387
388 if (stat(path, &sb) == -1)
389 fatal("stat %s: %s", path, strerror(errno));
390
391 return(S_ISREG(sb.st_mode));
392}
393
394static int
384remote_is_dir(struct sftp_conn *conn, char *path) 395remote_is_dir(struct sftp_conn *conn, char *path)
385{ 396{
386 Attrib *a; 397 Attrib *a;
@@ -494,6 +505,12 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag)
494 505
495 /* Only one match, dst may be file, directory or unspecified */ 506 /* Only one match, dst may be file, directory or unspecified */
496 if (g.gl_pathv[0] && g.gl_matchc == 1) { 507 if (g.gl_pathv[0] && g.gl_matchc == 1) {
508 if (!is_reg(g.gl_pathv[i])) {
509 error("Can't upload %s: not a regular file",
510 g.gl_pathv[0]);
511 err = 1;
512 goto out;
513 }
497 if (tmp_dst) { 514 if (tmp_dst) {
498 /* If directory specified, append filename */ 515 /* If directory specified, append filename */
499 if (remote_is_dir(conn, tmp_dst)) { 516 if (remote_is_dir(conn, tmp_dst)) {
@@ -525,6 +542,11 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag)
525 } 542 }
526 543
527 for (i = 0; g.gl_pathv[i]; i++) { 544 for (i = 0; g.gl_pathv[i]; i++) {
545 if (!is_reg(g.gl_pathv[i])) {
546 error("skipping non-regular file %s",
547 g.gl_pathv[i]);
548 continue;
549 }
528 if (infer_path(g.gl_pathv[i], &tmp)) { 550 if (infer_path(g.gl_pathv[i], &tmp)) {
529 err = -1; 551 err = -1;
530 goto out; 552 goto out;