summaryrefslogtreecommitdiff
path: root/msg.c
diff options
context:
space:
mode:
Diffstat (limited to 'msg.c')
-rw-r--r--msg.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/msg.c b/msg.c
index cd5f98c4f..5a7b8ca91 100644
--- a/msg.c
+++ b/msg.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: msg.c,v 1.15 2006/08/03 03:34:42 deraadt Exp $ */ 1/* $OpenBSD: msg.c,v 1.16 2015/01/15 09:40:00 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2002 Markus Friedl. All rights reserved. 3 * Copyright (c) 2002 Markus Friedl. All rights reserved.
4 * 4 *
@@ -34,17 +34,18 @@
34#include <unistd.h> 34#include <unistd.h>
35#include <stdarg.h> 35#include <stdarg.h>
36 36
37#include "buffer.h" 37#include "sshbuf.h"
38#include "ssherr.h"
38#include "log.h" 39#include "log.h"
39#include "atomicio.h" 40#include "atomicio.h"
40#include "msg.h" 41#include "msg.h"
41#include "misc.h" 42#include "misc.h"
42 43
43int 44int
44ssh_msg_send(int fd, u_char type, Buffer *m) 45ssh_msg_send(int fd, u_char type, struct sshbuf *m)
45{ 46{
46 u_char buf[5]; 47 u_char buf[5];
47 u_int mlen = buffer_len(m); 48 u_int mlen = sshbuf_len(m);
48 49
49 debug3("ssh_msg_send: type %u", (unsigned int)type & 0xff); 50 debug3("ssh_msg_send: type %u", (unsigned int)type & 0xff);
50 51
@@ -54,7 +55,7 @@ ssh_msg_send(int fd, u_char type, Buffer *m)
54 error("ssh_msg_send: write"); 55 error("ssh_msg_send: write");
55 return (-1); 56 return (-1);
56 } 57 }
57 if (atomicio(vwrite, fd, buffer_ptr(m), mlen) != mlen) { 58 if (atomicio(vwrite, fd, (u_char *)sshbuf_ptr(m), mlen) != mlen) {
58 error("ssh_msg_send: write"); 59 error("ssh_msg_send: write");
59 return (-1); 60 return (-1);
60 } 61 }
@@ -62,10 +63,11 @@ ssh_msg_send(int fd, u_char type, Buffer *m)
62} 63}
63 64
64int 65int
65ssh_msg_recv(int fd, Buffer *m) 66ssh_msg_recv(int fd, struct sshbuf *m)
66{ 67{
67 u_char buf[4]; 68 u_char buf[4], *p;
68 u_int msg_len; 69 u_int msg_len;
70 int r;
69 71
70 debug3("ssh_msg_recv entering"); 72 debug3("ssh_msg_recv entering");
71 73
@@ -79,9 +81,12 @@ ssh_msg_recv(int fd, Buffer *m)
79 error("ssh_msg_recv: read: bad msg_len %u", msg_len); 81 error("ssh_msg_recv: read: bad msg_len %u", msg_len);
80 return (-1); 82 return (-1);
81 } 83 }
82 buffer_clear(m); 84 sshbuf_reset(m);
83 buffer_append_space(m, msg_len); 85 if ((r = sshbuf_reserve(m, msg_len, &p)) != 0) {
84 if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) { 86 error("%s: buffer error: %s", __func__, ssh_err(r));
87 return -1;
88 }
89 if (atomicio(read, fd, p, msg_len) != msg_len) {
85 error("ssh_msg_recv: read: %s", strerror(errno)); 90 error("ssh_msg_recv: read: %s", strerror(errno));
86 return (-1); 91 return (-1);
87 } 92 }