upstream commit

update sftp client and server to new buffer API. pretty
 much just mechanical changes; with & ok markus
diff --git a/sftp-common.c b/sftp-common.c
index 70a929c..9c54d5c 100644
--- a/sftp-common.c
+++ b/sftp-common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-common.c,v 1.26 2014/01/09 03:26:00 guenther Exp $ */
+/* $OpenBSD: sftp-common.c,v 1.27 2015/01/14 13:54:13 djm Exp $ */
 /*
  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
  * Copyright (c) 2001 Damien Miller.  All rights reserved.
@@ -42,7 +42,8 @@
 #endif
 
 #include "xmalloc.h"
-#include "buffer.h"
+#include "ssherr.h"
+#include "sshbuf.h"
 #include "log.h"
 
 #include "sftp.h"
@@ -100,59 +101,81 @@
 }
 
 /* Decode attributes in buffer */
-Attrib *
-decode_attrib(Buffer *b)
+int
+decode_attrib(struct sshbuf *b, Attrib *a)
 {
-	static Attrib a;
+	int r;
 
-	attrib_clear(&a);
-	a.flags = buffer_get_int(b);
-	if (a.flags & SSH2_FILEXFER_ATTR_SIZE)
-		a.size = buffer_get_int64(b);
-	if (a.flags & SSH2_FILEXFER_ATTR_UIDGID) {
-		a.uid = buffer_get_int(b);
-		a.gid = buffer_get_int(b);
+	attrib_clear(a);
+	if ((r = sshbuf_get_u32(b, &a->flags)) != 0)
+		return r;
+	if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
+		if ((r = sshbuf_get_u64(b, &a->size)) != 0)
+			return r;
 	}
-	if (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
-		a.perm = buffer_get_int(b);
-	if (a.flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
-		a.atime = buffer_get_int(b);
-		a.mtime = buffer_get_int(b);
+	if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
+		if ((r = sshbuf_get_u32(b, &a->uid)) != 0 ||
+		    (r = sshbuf_get_u32(b, &a->gid)) != 0)
+			return r;
+	}
+	if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
+		if ((r = sshbuf_get_u32(b, &a->perm)) != 0)
+			return r;
+	}
+	if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
+		if ((r = sshbuf_get_u32(b, &a->atime)) != 0 ||
+		    (r = sshbuf_get_u32(b, &a->mtime)) != 0)
+			return r;
 	}
 	/* vendor-specific extensions */
-	if (a.flags & SSH2_FILEXFER_ATTR_EXTENDED) {
-		char *type, *data;
-		int i, count;
+	if (a->flags & SSH2_FILEXFER_ATTR_EXTENDED) {
+		char *type;
+		u_char *data;
+		size_t dlen;
+		u_int i, count;
 
-		count = buffer_get_int(b);
+		if ((r = sshbuf_get_u32(b, &count)) != 0)
+			fatal("%s: buffer error: %s", __func__, ssh_err(r));
 		for (i = 0; i < count; i++) {
-			type = buffer_get_string(b, NULL);
-			data = buffer_get_string(b, NULL);
-			debug3("Got file attribute \"%s\"", type);
+			if ((r = sshbuf_get_cstring(b, &type, NULL)) != 0 ||
+			    (r = sshbuf_get_string(b, &data, &dlen)) != 0)
+				return r;
+			debug3("Got file attribute \"%.100s\" len %zu",
+			    type, dlen);
 			free(type);
 			free(data);
 		}
 	}
-	return &a;
+	return 0;
 }
 
 /* Encode attributes to buffer */
-void
-encode_attrib(Buffer *b, const Attrib *a)
+int
+encode_attrib(struct sshbuf *b, const Attrib *a)
 {
-	buffer_put_int(b, a->flags);
-	if (a->flags & SSH2_FILEXFER_ATTR_SIZE)
-		buffer_put_int64(b, a->size);
+	int r;
+
+	if ((r = sshbuf_put_u32(b, a->flags)) != 0)
+		return r;
+	if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
+		if ((r = sshbuf_put_u64(b, a->size)) != 0)
+			return r;
+	}
 	if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
-		buffer_put_int(b, a->uid);
-		buffer_put_int(b, a->gid);
+		if ((r = sshbuf_put_u32(b, a->uid)) != 0 ||
+		    (r = sshbuf_put_u32(b, a->gid)) != 0)
+			return r;
 	}
-	if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
-		buffer_put_int(b, a->perm);
+	if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
+		if ((r = sshbuf_put_u32(b, a->perm)) != 0)
+			return r;
+	}
 	if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
-		buffer_put_int(b, a->atime);
-		buffer_put_int(b, a->mtime);
+		if ((r = sshbuf_put_u32(b, a->atime)) != 0 ||
+		    (r = sshbuf_put_u32(b, a->mtime)) != 0)
+			return r;
 	}
+	return 0;
 }
 
 /* Convert from SSH2_FX_ status to text error message */