Please test snapshots for 3.0 release

Kevin Steves stevesk at pobox.com
Sat Oct 27 09:57:26 EST 2001


On 14 Oct 2001, Sturle Sunde wrote:
:I have tested with native compilers on six different platforms, and
:get lot's of warnings (mostly prototype/argument mismatches).

after 3.0, we might revisit this:

this patch changes the buffer/packet interface to use void* vs. char*.

Index: buffer.h
===================================================================
RCS file: /cvs/src/usr.bin/ssh/buffer.h,v
retrieving revision 1.9
diff -u -r1.9 buffer.h
--- buffer.h	2001/06/26 17:27:23	1.9
+++ buffer.h	2001/08/09 17:50:07
@@ -17,7 +17,7 @@
 #define BUFFER_H

 typedef struct {
-	char	*buf;		/* Buffer for data. */
+	u_char	*buf;		/* Buffer for data. */
 	u_int	 alloc;		/* Number of bytes allocated for data. */
 	u_int	 offset;	/* Offset of first byte containing data. */
 	u_int	 end;		/* Offset of last byte containing data. */
@@ -28,12 +28,12 @@
 void	 buffer_free(Buffer *);

 u_int	 buffer_len(Buffer *);
-char	*buffer_ptr(Buffer *);
+void	*buffer_ptr(Buffer *);

-void	 buffer_append(Buffer *, const char *, u_int);
-void	 buffer_append_space(Buffer *, char **, u_int);
+void	 buffer_append(Buffer *, const void *, u_int);
+void	*buffer_append_space(Buffer *, u_int);

-void	 buffer_get(Buffer *, char *, u_int);
+void	 buffer_get(Buffer *, void *, u_int);

 void	 buffer_consume(Buffer *, u_int);
 void	 buffer_consume_end(Buffer *, u_int);
Index: buffer.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/buffer.c,v
retrieving revision 1.13
diff -u -r1.13 buffer.c
--- buffer.c	2001/04/12 19:15:24	1.13
+++ buffer.c	2001/08/09 17:50:07
@@ -53,11 +53,11 @@
 /* Appends data to the buffer, expanding it if necessary. */

 void
-buffer_append(Buffer *buffer, const char *data, u_int len)
+buffer_append(Buffer *buffer, const void *data, u_int len)
 {
-	char *cp;
-	buffer_append_space(buffer, &cp, len);
-	memcpy(cp, data, len);
+	void *p;
+	p = buffer_append_space(buffer, len);
+	memcpy(p, data, len);
 }

 /*
@@ -66,9 +66,11 @@
  * to the allocated region.
  */

-void
-buffer_append_space(Buffer *buffer, char **datap, u_int len)
+void *
+buffer_append_space(Buffer *buffer, u_int len)
 {
+	void *p;
+
 	/* If the buffer is empty, start using it from the beginning. */
 	if (buffer->offset == buffer->end) {
 		buffer->offset = 0;
@@ -77,9 +79,9 @@
 restart:
 	/* If there is enough space to store all data, store it now. */
 	if (buffer->end + len < buffer->alloc) {
-		*datap = buffer->buf + buffer->end;
+		p = buffer->buf + buffer->end;
 		buffer->end += len;
-		return;
+		return p;
 	}
 	/*
 	 * If the buffer is quite empty, but all data is at the end, move the
@@ -96,6 +98,7 @@
 	buffer->alloc += len + 32768;
 	buffer->buf = xrealloc(buffer->buf, buffer->alloc);
 	goto restart;
+	/* NOTREACHED */
 }

 /* Returns the number of bytes of data in the buffer. */
@@ -109,7 +112,7 @@
 /* Gets data from the beginning of the buffer. */

 void
-buffer_get(Buffer *buffer, char *buf, u_int len)
+buffer_get(Buffer *buffer, void *buf, u_int len)
 {
 	if (len > buffer->end - buffer->offset)
 		fatal("buffer_get: trying to get more bytes %d than in buffer %d",
@@ -140,7 +143,7 @@

 /* Returns a pointer to the first used byte in the buffer. */

-char *
+void *
 buffer_ptr(Buffer *buffer)
 {
 	return buffer->buf + buffer->offset;
Index: bufaux.h
===================================================================
RCS file: /cvs/src/usr.bin/ssh/bufaux.h,v
retrieving revision 1.13
diff -u -r1.13 bufaux.h
--- bufaux.h	2001/06/26 17:27:22	1.13
+++ bufaux.h	2001/08/09 17:50:07
@@ -32,7 +32,7 @@
 int     buffer_get_char(Buffer *);
 void    buffer_put_char(Buffer *, int);

-char   *buffer_get_string(Buffer *, u_int *);
+void   *buffer_get_string(Buffer *, u_int *);
 void    buffer_put_string(Buffer *, const void *, u_int);
 void	buffer_put_cstring(Buffer *, const char *);

Index: bufaux.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/bufaux.c,v
retrieving revision 1.17
diff -u -r1.17 bufaux.c
--- bufaux.c	2001/01/21 19:05:45	1.17
+++ bufaux.c	2001/08/09 17:50:07
@@ -187,11 +187,11 @@
  * will be stored there.  A null character will be automatically appended
  * to the returned string, and is not counted in length.
  */
-char *
+void *
 buffer_get_string(Buffer *buffer, u_int *length_ptr)
 {
 	u_int len;
-	char *value;
+	u_char *value;
 	/* Get the length. */
 	len = buffer_get_int(buffer);
 	if (len > 256 * 1024)
Index: packet.h
===================================================================
RCS file: /cvs/src/usr.bin/ssh/packet.h,v
retrieving revision 1.25
diff -u -r1.25 packet.h
--- packet.h	2001/06/26 17:27:24	1.25
+++ packet.h	2001/08/09 17:50:08
@@ -35,9 +35,9 @@
 void     packet_put_int(u_int value);
 void     packet_put_bignum(BIGNUM * value);
 void     packet_put_bignum2(BIGNUM * value);
-void     packet_put_string(const char *buf, u_int len);
+void     packet_put_string(const void *buf, u_int len);
 void     packet_put_cstring(const char *str);
-void     packet_put_raw(const char *buf, u_int len);
+void     packet_put_raw(const void *buf, u_int len);
 void     packet_send(void);

 int      packet_read(int *payload_len_ptr);
@@ -49,8 +49,8 @@
 u_int	 packet_get_int(void);
 void     packet_get_bignum(BIGNUM * value, int *length_ptr);
 void     packet_get_bignum2(BIGNUM * value, int *length_ptr);
-char	*packet_get_raw(int *length_ptr);
-char    *packet_get_string(u_int *length_ptr);
+void	*packet_get_raw(int *length_ptr);
+void	*packet_get_string(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)));

Index: packet.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/packet.c,v
retrieving revision 1.69
diff -u -r1.69 packet.c
--- packet.c	2001/06/25 08:25:38	1.69
+++ packet.c	2001/08/09 17:50:15
@@ -326,7 +326,7 @@
 	buffer_put_int(&outgoing_packet, value);
 }
 void
-packet_put_string(const char *buf, u_int len)
+packet_put_string(const void *buf, u_int len)
 {
 	buffer_put_string(&outgoing_packet, buf, len);
 }
@@ -336,7 +336,7 @@
 	buffer_put_cstring(&outgoing_packet, str);
 }
 void
-packet_put_raw(const char *buf, u_int len)
+packet_put_raw(const void *buf, u_int len)
 {
 	buffer_append(&outgoing_packet, buf, len);
 }
@@ -409,7 +409,7 @@
 	/* Append to output. */
 	PUT_32BIT(buf, len);
 	buffer_append(&output, buf, 4);
-	buffer_append_space(&output, &cp, buffer_len(&outgoing_packet));
+	cp = buffer_append_space(&output, buffer_len(&outgoing_packet));
 	cipher_encrypt(&send_context, cp, buffer_ptr(&outgoing_packet),
 		       buffer_len(&outgoing_packet));

@@ -533,7 +533,7 @@
 	padlen = block_size - (len % block_size);
 	if (padlen < 4)
 		padlen += block_size;
-	buffer_append_space(&outgoing_packet, &cp, padlen);
+	cp = buffer_append_space(&outgoing_packet, padlen);
 	if (enc && enc->cipher->number != SSH_CIPHER_NONE) {
 		/* random padding */
 		for (i = 0; i < padlen; i++) {
@@ -561,7 +561,7 @@
 		DBG(debug("done calc MAC out #%d", seqnr));
 	}
 	/* encrypt packet and append to output buffer. */
-	buffer_append_space(&output, &cp, buffer_len(&outgoing_packet));
+	cp = buffer_append_space(&output, buffer_len(&outgoing_packet));
 	cipher_encrypt(&send_context, cp, buffer_ptr(&outgoing_packet),
 	    buffer_len(&outgoing_packet));
 	/* append unencrypted MAC */
@@ -721,7 +721,7 @@

 	/* Decrypt data to incoming_packet. */
 	buffer_clear(&incoming_packet);
-	buffer_append_space(&incoming_packet, &cp, padded_len);
+	cp = buffer_append_space(&incoming_packet, padded_len);
 	cipher_decrypt(&receive_context, cp, buffer_ptr(&input), padded_len);

 	buffer_consume(&input, padded_len);
@@ -790,7 +790,7 @@
 		if (buffer_len(&input) < block_size)
 			return SSH_MSG_NONE;
 		buffer_clear(&incoming_packet);
-		buffer_append_space(&incoming_packet, &cp, block_size);
+		cp = buffer_append_space(&incoming_packet, block_size);
 		cipher_decrypt(&receive_context, cp, buffer_ptr(&input),
 		    block_size);
 		ucp = (u_char *) buffer_ptr(&incoming_packet);
@@ -819,7 +819,7 @@
 	fprintf(stderr, "read_poll enc/full: ");
 	buffer_dump(&input);
 #endif
-	buffer_append_space(&incoming_packet, &cp, need);
+	cp = buffer_append_space(&incoming_packet, need);
 	cipher_decrypt(&receive_context, cp, buffer_ptr(&input), need);
 	buffer_consume(&input, need);
 	/*
@@ -839,7 +839,8 @@
 		log("incoming seqnr wraps around");

 	/* get padlen */
-	cp = buffer_ptr(&incoming_packet) + 4;
+	cp = buffer_ptr(&incoming_packet);
+	cp += 4;
 	padlen = (u_char) *cp;
 	DBG(debug("input: padlen %d", padlen));
 	if (padlen < 4)
@@ -983,7 +984,7 @@
 	*length_ptr = buffer_get_bignum2(&incoming_packet, value);
 }

-char *
+void *
 packet_get_raw(int *length_ptr)
 {
 	int bytes = buffer_len(&incoming_packet);
@@ -1005,7 +1006,7 @@
  * integer into which the length of the string is stored.
  */

-char *
+void *
 packet_get_string(u_int *length_ptr)
 {
 	return buffer_get_string(&incoming_packet, length_ptr);
Index: authfile.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/authfile.c,v
retrieving revision 1.37
diff -u -r1.37 authfile.c
--- authfile.c	2001/06/23 15:12:17	1.37
+++ authfile.c	2001/08/09 17:50:15
@@ -128,7 +128,7 @@
 	buffer_put_cstring(&encrypted, comment);

 	/* Allocate space for the private part of the key in the buffer. */
-	buffer_append_space(&encrypted, &cp, buffer_len(&buffer));
+	cp = buffer_append_space(&encrypted, buffer_len(&buffer));

 	cipher_set_key_string(&ciphercontext, cipher, passphrase);
 	cipher_encrypt(&ciphercontext, (u_char *) cp,
@@ -239,7 +239,7 @@
 	lseek(fd, (off_t) 0, SEEK_SET);

 	buffer_init(&buffer);
-	buffer_append_space(&buffer, &cp, len);
+	cp = buffer_append_space(&buffer, len);

 	if (read(fd, cp, (size_t) len) != (size_t) len) {
 		debug("Read from key file %.200s failed: %.100s", filename,
@@ -324,7 +324,7 @@
 	lseek(fd, (off_t) 0, SEEK_SET);

 	buffer_init(&buffer);
-	buffer_append_space(&buffer, &cp, len);
+	cp = buffer_append_space(&buffer, len);

 	if (read(fd, cp, (size_t) len) != (size_t) len) {
 		debug("Read from key file %.200s failed: %.100s", filename,
@@ -378,7 +378,7 @@
 	}
 	/* Initialize space for decrypted data. */
 	buffer_init(&decrypted);
-	buffer_append_space(&decrypted, &cp, buffer_len(&buffer));
+	cp = buffer_append_space(&decrypted, buffer_len(&buffer));

 	/* Rest of the buffer is encrypted.  Decrypt it using the passphrase. */
 	cipher_set_key_string(&ciphercontext, cipher, passphrase);





More information about the openssh-unix-dev mailing list