changeset 1754:064f5be2fc45

Add buf_decrpos()
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Oct 2020 18:56:45 +0800
parents 7c0fcd19e492
children 9efceb851bea 4c5599435084
files buffer.c buffer.h keyimport.c signkey.c svr-authpubkey.c
diffstat 5 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/buffer.c	Fri Oct 23 20:53:58 2020 +0800
+++ b/buffer.c	Sat Oct 24 18:56:45 2020 +0800
@@ -125,18 +125,23 @@
 	}
 }
 
-/* increment the position by incr, negative values are allowed, to
- * decrement the pos*/
-void buf_incrpos(buffer* buf,  int incr) {
+/* increment the position by incr */
+void buf_incrpos(buffer* buf, unsigned int incr) {
 	if (incr > BUF_MAX_INCR 
-		|| incr < -BUF_MAX_INCR 
-		|| (unsigned int)((int)buf->pos + incr) > buf->len
-		|| ((int)buf->pos + incr) < 0) {
+		|| (buf->pos + incr) > buf->len) {
 		dropbear_exit("Bad buf_incrpos");
 	}
 	buf->pos += incr;
 }
 
+/* decrement the position by decr */
+void buf_decrpos(buffer* buf, unsigned int decr) {
+	if (decr > buf->pos) {
+		dropbear_exit("Bad buf_decrpos");
+	}
+	buf->pos -= decr;
+}
+
 /* Get a byte from the buffer and increment the pos */
 unsigned char buf_getbyte(buffer* buf) {
 
--- a/buffer.h	Fri Oct 23 20:53:58 2020 +0800
+++ b/buffer.h	Sat Oct 24 18:56:45 2020 +0800
@@ -49,7 +49,8 @@
 void buf_setlen(buffer* buf, unsigned int len);
 void buf_incrlen(buffer* buf, unsigned int incr);
 void buf_setpos(buffer* buf, unsigned int pos);
-void buf_incrpos(buffer* buf, int incr); /* -ve is ok, to go backwards */
+void buf_incrpos(buffer* buf, unsigned int incr);
+void buf_decrpos(buffer* buf, unsigned int decr);
 void buf_incrwritepos(buffer* buf, unsigned int incr);
 unsigned char buf_getbyte(buffer* buf);
 unsigned char buf_getbool(buffer* buf);
--- a/keyimport.c	Fri Oct 23 20:53:58 2020 +0800
+++ b/keyimport.c	Sat Oct 24 18:56:45 2020 +0800
@@ -637,7 +637,7 @@
 				buf_incrpos(blobbuf, 8);
 				buf_eatstring(blobbuf);
 				buf_eatstring(blobbuf);
-				buf_incrpos(blobbuf, -SSH_SIGNKEY_ED25519_LEN-4);
+				buf_decrpos(blobbuf, SSH_SIGNKEY_ED25519_LEN+4);
 				if (buf_get_ed25519_priv_key(blobbuf, retkey->ed25519key)
 						== DROPBEAR_SUCCESS) {
 					errmsg = NULL;
--- a/signkey.c	Fri Oct 23 20:53:58 2020 +0800
+++ b/signkey.c	Sat Oct 24 18:56:45 2020 +0800
@@ -235,7 +235,7 @@
 	*type = keytype;
 
 	/* Rewind the buffer back before "ssh-rsa" etc */
-	buf_incrpos(buf, -len - 4);
+	buf_decrpos(buf, len + 4);
 
 #if DROPBEAR_DSS
 	if (keytype == DROPBEAR_SIGNKEY_DSS) {
@@ -316,7 +316,7 @@
 	*type = keytype;
 
 	/* Rewind the buffer back before "ssh-rsa" etc */
-	buf_incrpos(buf, -len - 4);
+	buf_decrpos(buf, len + 4);
 
 #if DROPBEAR_DSS
 	if (keytype == DROPBEAR_SIGNKEY_DSS) {
--- a/svr-authpubkey.c	Fri Oct 23 20:53:58 2020 +0800
+++ b/svr-authpubkey.c	Sat Oct 24 18:56:45 2020 +0800
@@ -294,7 +294,7 @@
 				is_comment = 1;
 				break;
 			}
-			buf_incrpos(line, -1);
+			buf_decrpos(line, 1);
 			break;
 		}
 		if (is_comment) {