Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/puffs/mount_psshfs Ensure psshfs_node_read() comple...



details:   https://anonhg.NetBSD.org/src/rev/43ff2aeda2c9
branches:  trunk
changeset: 772900:43ff2aeda2c9
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Fri Jan 20 22:07:58 2012 +0000

description:
Ensure psshfs_node_read() completely reads all data before return.
Fixes file corruption in psshfs exposed with kernel MAXPHYS at 128KiB.

diffstat:

 usr.sbin/puffs/mount_psshfs/node.c |  16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diffs (52 lines):

diff -r 76fe3c388f08 -r 43ff2aeda2c9 usr.sbin/puffs/mount_psshfs/node.c
--- a/usr.sbin/puffs/mount_psshfs/node.c        Fri Jan 20 18:47:04 2012 +0000
+++ b/usr.sbin/puffs/mount_psshfs/node.c        Fri Jan 20 22:07:58 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: node.c,v 1.63 2011/08/12 04:14:00 riastradh Exp $      */
+/*     $NetBSD: node.c,v 1.64 2012/01/20 22:07:58 jakllsch Exp $       */
 
 /*
  * Copyright (c) 2006-2009  Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: node.c,v 1.63 2011/08/12 04:14:00 riastradh Exp $");
+__RCSID("$NetBSD: node.c,v 1.64 2012/01/20 22:07:58 jakllsch Exp $");
 #endif /* !lint */
 
 #include <assert.h>
@@ -525,6 +525,7 @@
                goto farout;
        }
 
+again:
        readlen = *resid;
        psbuf_req_data(pb, SSH_FXP_READ, reqid, psn->fhand_r, psn->fhand_r_len);
        psbuf_put_8(pb, offset);
@@ -546,8 +547,11 @@
        GETRESPONSE(pb, pctx->sshfd_data);
 
        rv = psbuf_do_data(pb, buf, &readlen);
-       if (rv == 0)
+       if (rv == 0) {
                *resid -= readlen;
+               buf += readlen;
+               offset += readlen;
+       }
 
  out:
        if (max_reads && --psn->readcount >= max_reads) {
@@ -559,6 +563,12 @@
                TAILQ_REMOVE(&psn->pw, pwp, pw_entries);
        }
 
+       if (rv == 0 && *resid > 0) {
+               reqid = NEXTREQ(pctx);
+               psbuf_recycleout(pb);
+               goto again;
+       }
+
  farout:
        /* check if we need a lazyclose */
        if (psn->stat & PSN_HANDLECLOSE && psn->fhand_r) {



Home | Main Index | Thread Index | Old Index