summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--bufaux.c18
-rw-r--r--buffer.h3
-rw-r--r--channels.c9
-rw-r--r--packet.c8
-rw-r--r--packet.h3
6 files changed, 36 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 4ac32e57f..e7fd87ba8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -58,6 +58,10 @@
- jmc@cvs.openbsd.org 2008/05/07 08:00:14
[sshd_config.5]
sort;
+ - markus@cvs.openbsd.org 2008/05/08 06:59:01
+ [bufaux.c buffer.h channels.c packet.c packet.h]
+ avoid extra malloc/copy/free when receiving data over the net;
+ ~10% speedup for localhost-scp; ok djm@
20080403
- (djm) [openbsd-compat/bsd-poll.c] Include stdlib.h to avoid compile-
@@ -3918,4 +3922,4 @@
OpenServer 6 and add osr5bigcrypt support so when someone migrates
passwords between UnixWare and OpenServer they will still work. OK dtucker@
-$Id: ChangeLog,v 1.4918 2008/05/19 04:59:02 djm Exp $
+$Id: ChangeLog,v 1.4919 2008/05/19 04:59:37 djm Exp $
diff --git a/bufaux.c b/bufaux.c
index cbdc22c64..f03363994 100644
--- a/bufaux.c
+++ b/bufaux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bufaux.c,v 1.44 2006/08/03 03:34:41 deraadt Exp $ */
+/* $OpenBSD: bufaux.c,v 1.45 2008/05/08 06:59:01 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -197,6 +197,22 @@ buffer_get_string(Buffer *buffer, u_int *length_ptr)
return (ret);
}
+void *
+buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr)
+{
+ void *ptr;
+ u_int len;
+
+ len = buffer_get_int(buffer);
+ if (len > 256 * 1024)
+ fatal("buffer_get_string_ptr: bad string length %u", len);
+ ptr = buffer_ptr(buffer);
+ buffer_consume(buffer, len);
+ if (length_ptr)
+ *length_ptr = len;
+ return (ptr);
+}
+
/*
* Stores and arbitrary binary string in the buffer.
*/
diff --git a/buffer.h b/buffer.h
index ecc4aea83..d0f354ee7 100644
--- a/buffer.h
+++ b/buffer.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.h,v 1.16 2006/08/03 03:34:41 deraadt Exp $ */
+/* $OpenBSD: buffer.h,v 1.17 2008/05/08 06:59:01 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -66,6 +66,7 @@ int buffer_get_char(Buffer *);
void buffer_put_char(Buffer *, int);
void *buffer_get_string(Buffer *, u_int *);
+void *buffer_get_string_ptr(Buffer *, u_int *);
void buffer_put_string(Buffer *, const void *, u_int);
void buffer_put_cstring(Buffer *, const char *);
diff --git a/channels.c b/channels.c
index b6bd901f0..05c23e59c 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.273 2008/04/02 21:36:51 markus Exp $ */
+/* $OpenBSD: channels.c,v 1.274 2008/05/08 06:59:01 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -2012,7 +2012,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
return;
/* Get the data. */
- data = packet_get_string(&data_len);
+ data = packet_get_string_ptr(&data_len);
/*
* Ignore data for protocol > 1.3 if output end is no longer open.
@@ -2026,7 +2026,6 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
c->local_window -= data_len;
c->local_consumed += data_len;
}
- xfree(data);
return;
}
@@ -2038,17 +2037,15 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
if (data_len > c->local_window) {
logit("channel %d: rcvd too much data %d, win %d",
c->self, data_len, c->local_window);
- xfree(data);
return;
}
c->local_window -= data_len;
}
- packet_check_eom();
if (c->datagram)
buffer_put_string(&c->output, data, data_len);
else
buffer_append(&c->output, data, data_len);
- xfree(data);
+ packet_check_eom();
}
/* ARGSUSED */
diff --git a/packet.c b/packet.c
index 6afe24b9f..a34c040d6 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.151 2008/02/22 20:44:02 dtucker Exp $ */
+/* $OpenBSD: packet.c,v 1.152 2008/05/08 06:59:01 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1332,6 +1332,12 @@ packet_get_string(u_int *length_ptr)
return buffer_get_string(&incoming_packet, length_ptr);
}
+void *
+packet_get_string_ptr(u_int *length_ptr)
+{
+ return buffer_get_string_ptr(&incoming_packet, length_ptr);
+}
+
/*
* Sends a diagnostic message from the server to the client. This message
* can be sent at any time (but not while constructing another message). The
diff --git a/packet.h b/packet.h
index c1b9b3bd1..927e0831c 100644
--- a/packet.h
+++ b/packet.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.h,v 1.46 2008/02/22 20:44:02 dtucker Exp $ */
+/* $OpenBSD: packet.h,v 1.47 2008/05/08 06:59:01 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -58,6 +58,7 @@ void packet_get_bignum(BIGNUM * value);
void packet_get_bignum2(BIGNUM * value);
void *packet_get_raw(u_int *length_ptr);
void *packet_get_string(u_int *length_ptr);
+void *packet_get_string_ptr(u_int *length_ptr);
void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));