mirror of
https://github.com/clearml/dropbear
synced 2025-03-10 05:50:15 +00:00
Add buf_decrpos()
This commit is contained in:
parent
1a208c460b
commit
037d26f055
17
buffer.c
17
buffer.c
@ -125,18 +125,23 @@ void buf_incrwritepos(buffer* buf, unsigned int incr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* increment the position by incr, negative values are allowed, to
|
/* increment the position by incr */
|
||||||
* decrement the pos*/
|
void buf_incrpos(buffer* buf, unsigned int incr) {
|
||||||
void buf_incrpos(buffer* buf, int incr) {
|
|
||||||
if (incr > BUF_MAX_INCR
|
if (incr > BUF_MAX_INCR
|
||||||
|| incr < -BUF_MAX_INCR
|
|| (buf->pos + incr) > buf->len) {
|
||||||
|| (unsigned int)((int)buf->pos + incr) > buf->len
|
|
||||||
|| ((int)buf->pos + incr) < 0) {
|
|
||||||
dropbear_exit("Bad buf_incrpos");
|
dropbear_exit("Bad buf_incrpos");
|
||||||
}
|
}
|
||||||
buf->pos += incr;
|
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 */
|
/* Get a byte from the buffer and increment the pos */
|
||||||
unsigned char buf_getbyte(buffer* buf) {
|
unsigned char buf_getbyte(buffer* buf) {
|
||||||
|
|
||||||
|
3
buffer.h
3
buffer.h
@ -49,7 +49,8 @@ buffer* buf_newcopy(const buffer* buf);
|
|||||||
void buf_setlen(buffer* buf, unsigned int len);
|
void buf_setlen(buffer* buf, unsigned int len);
|
||||||
void buf_incrlen(buffer* buf, unsigned int incr);
|
void buf_incrlen(buffer* buf, unsigned int incr);
|
||||||
void buf_setpos(buffer* buf, unsigned int pos);
|
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);
|
void buf_incrwritepos(buffer* buf, unsigned int incr);
|
||||||
unsigned char buf_getbyte(buffer* buf);
|
unsigned char buf_getbyte(buffer* buf);
|
||||||
unsigned char buf_getbool(buffer* buf);
|
unsigned char buf_getbool(buffer* buf);
|
||||||
|
@ -637,7 +637,7 @@ static sign_key *openssh_read(const char *filename, const char * UNUSED(passphra
|
|||||||
buf_incrpos(blobbuf, 8);
|
buf_incrpos(blobbuf, 8);
|
||||||
buf_eatstring(blobbuf);
|
buf_eatstring(blobbuf);
|
||||||
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)
|
if (buf_get_ed25519_priv_key(blobbuf, retkey->ed25519key)
|
||||||
== DROPBEAR_SUCCESS) {
|
== DROPBEAR_SUCCESS) {
|
||||||
errmsg = NULL;
|
errmsg = NULL;
|
||||||
|
@ -235,7 +235,7 @@ int buf_get_pub_key(buffer *buf, sign_key *key, enum signkey_type *type) {
|
|||||||
*type = keytype;
|
*type = keytype;
|
||||||
|
|
||||||
/* Rewind the buffer back before "ssh-rsa" etc */
|
/* Rewind the buffer back before "ssh-rsa" etc */
|
||||||
buf_incrpos(buf, -len - 4);
|
buf_decrpos(buf, len + 4);
|
||||||
|
|
||||||
#if DROPBEAR_DSS
|
#if DROPBEAR_DSS
|
||||||
if (keytype == DROPBEAR_SIGNKEY_DSS) {
|
if (keytype == DROPBEAR_SIGNKEY_DSS) {
|
||||||
@ -316,7 +316,7 @@ int buf_get_priv_key(buffer *buf, sign_key *key, enum signkey_type *type) {
|
|||||||
*type = keytype;
|
*type = keytype;
|
||||||
|
|
||||||
/* Rewind the buffer back before "ssh-rsa" etc */
|
/* Rewind the buffer back before "ssh-rsa" etc */
|
||||||
buf_incrpos(buf, -len - 4);
|
buf_decrpos(buf, len + 4);
|
||||||
|
|
||||||
#if DROPBEAR_DSS
|
#if DROPBEAR_DSS
|
||||||
if (keytype == DROPBEAR_SIGNKEY_DSS) {
|
if (keytype == DROPBEAR_SIGNKEY_DSS) {
|
||||||
|
@ -294,7 +294,7 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
|
|||||||
is_comment = 1;
|
is_comment = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf_incrpos(line, -1);
|
buf_decrpos(line, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (is_comment) {
|
if (is_comment) {
|
||||||
|
Loading…
Reference in New Issue
Block a user