Skip to content

Commit 037d26f

Browse files
committed
Add buf_decrpos()
1 parent 1a208c4 commit 037d26f

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

buffer.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,23 @@ void buf_incrwritepos(buffer* buf, unsigned int incr) {
125125
}
126126
}
127127

128-
/* increment the position by incr, negative values are allowed, to
129-
* decrement the pos*/
130-
void buf_incrpos(buffer* buf, int incr) {
128+
/* increment the position by incr */
129+
void buf_incrpos(buffer* buf, unsigned int incr) {
131130
if (incr > BUF_MAX_INCR
132-
|| incr < -BUF_MAX_INCR
133-
|| (unsigned int)((int)buf->pos + incr) > buf->len
134-
|| ((int)buf->pos + incr) < 0) {
131+
|| (buf->pos + incr) > buf->len) {
135132
dropbear_exit("Bad buf_incrpos");
136133
}
137134
buf->pos += incr;
138135
}
139136

137+
/* decrement the position by decr */
138+
void buf_decrpos(buffer* buf, unsigned int decr) {
139+
if (decr > buf->pos) {
140+
dropbear_exit("Bad buf_decrpos");
141+
}
142+
buf->pos -= decr;
143+
}
144+
140145
/* Get a byte from the buffer and increment the pos */
141146
unsigned char buf_getbyte(buffer* buf) {
142147

buffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ buffer* buf_newcopy(const buffer* buf);
4949
void buf_setlen(buffer* buf, unsigned int len);
5050
void buf_incrlen(buffer* buf, unsigned int incr);
5151
void buf_setpos(buffer* buf, unsigned int pos);
52-
void buf_incrpos(buffer* buf, int incr); /* -ve is ok, to go backwards */
52+
void buf_incrpos(buffer* buf, unsigned int incr);
53+
void buf_decrpos(buffer* buf, unsigned int decr);
5354
void buf_incrwritepos(buffer* buf, unsigned int incr);
5455
unsigned char buf_getbyte(buffer* buf);
5556
unsigned char buf_getbool(buffer* buf);

keyimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static sign_key *openssh_read(const char *filename, const char * UNUSED(passphra
637637
buf_incrpos(blobbuf, 8);
638638
buf_eatstring(blobbuf);
639639
buf_eatstring(blobbuf);
640-
buf_incrpos(blobbuf, -SSH_SIGNKEY_ED25519_LEN-4);
640+
buf_decrpos(blobbuf, SSH_SIGNKEY_ED25519_LEN+4);
641641
if (buf_get_ed25519_priv_key(blobbuf, retkey->ed25519key)
642642
== DROPBEAR_SUCCESS) {
643643
errmsg = NULL;

signkey.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ int buf_get_pub_key(buffer *buf, sign_key *key, enum signkey_type *type) {
235235
*type = keytype;
236236

237237
/* Rewind the buffer back before "ssh-rsa" etc */
238-
buf_incrpos(buf, -len - 4);
238+
buf_decrpos(buf, len + 4);
239239

240240
#if DROPBEAR_DSS
241241
if (keytype == DROPBEAR_SIGNKEY_DSS) {
@@ -316,7 +316,7 @@ int buf_get_priv_key(buffer *buf, sign_key *key, enum signkey_type *type) {
316316
*type = keytype;
317317

318318
/* Rewind the buffer back before "ssh-rsa" etc */
319-
buf_incrpos(buf, -len - 4);
319+
buf_decrpos(buf, len + 4);
320320

321321
#if DROPBEAR_DSS
322322
if (keytype == DROPBEAR_SIGNKEY_DSS) {

svr-authpubkey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
294294
is_comment = 1;
295295
break;
296296
}
297-
buf_incrpos(line, -1);
297+
buf_decrpos(line, 1);
298298
break;
299299
}
300300
if (is_comment) {

0 commit comments

Comments
 (0)