diff --git a/ssh/kex.c b/ssh/kex.c index d42aa05..fda2988 100644 --- a/ssh/kex.c +++ b/ssh/kex.c @@ -246,15 +246,16 @@ int kex_input_kexinit(int type, u_int32_t seq, struct ssh *ssh) { Kex *kex = ssh->kex; - char *ptr; - u_int i, dlen; + u_char *ptr; + u_int i; + size_t dlen; int r; debug("SSH2_MSG_KEXINIT received"); if (kex == NULL) return SSH_ERR_INVALID_ARGUMENT; - ptr = ssh_packet_get_raw(ssh, &dlen); + ptr = sshpkt_ptr(ssh, &dlen); if ((r = sshbuf_put(kex->peer, ptr, dlen)) != 0) return r; diff --git a/ssh/packet.c b/ssh/packet.c index 951f711..7d6f750 100644 --- a/ssh/packet.c +++ b/ssh/packet.c @@ -1902,16 +1902,6 @@ ssh_packet_get_ecpoint(struct ssh *ssh, const EC_GROUP *curve, EC_POINT *point) fatal("%s: %s", __func__, ssh_err(r)); } -void * -ssh_packet_get_raw(struct ssh *ssh, u_int *length_ptr) -{ - u_int bytes = sshbuf_len(ssh->state->incoming_packet); - - if (length_ptr != NULL) - *length_ptr = bytes; - return sshbuf_ptr(ssh->state->incoming_packet); -} - int ssh_packet_remaining(struct ssh *ssh) { @@ -2833,6 +2823,15 @@ sshpkt_get_end(struct ssh *ssh) return 0; } +u_char * +sshpkt_ptr(struct ssh *ssh, size_t *lenp) +{ + if (lenp != NULL) + *lenp = sshbuf_len(ssh->state->incoming_packet); + return sshbuf_ptr(ssh->state->incoming_packet); +} + + /* start a new packet */ int diff --git a/ssh/packet.h b/ssh/packet.h index c74b927..5c8a816 100644 --- a/ssh/packet.h +++ b/ssh/packet.h @@ -119,7 +119,6 @@ u_int64_t ssh_packet_get_int64(struct ssh *); void ssh_packet_get_bignum(struct ssh *, BIGNUM * value); void ssh_packet_get_bignum2(struct ssh *, BIGNUM * value); void ssh_packet_get_ecpoint(struct ssh *, const EC_GROUP *, EC_POINT *); -void *ssh_packet_get_raw(struct ssh *, u_int *length_ptr); void *ssh_packet_get_string(struct ssh *, u_int *length_ptr); char *ssh_packet_get_cstring(struct ssh *, u_int *length_ptr); const void *ssh_packet_get_string_ptr(struct ssh *, u_int *length_ptr); @@ -327,5 +326,6 @@ int sshpkt_get_ec(struct ssh *ssh, EC_POINT *v, const EC_GROUP *g); int sshpkt_get_bignum1(struct ssh *ssh, BIGNUM *v); int sshpkt_get_bignum2(struct ssh *ssh, BIGNUM *v); int sshpkt_get_end(struct ssh *ssh); +u_char *sshpkt_ptr(struct ssh *, size_t *lenp); #endif /* PACKET_H */ diff --git a/ssh/ssh_api.c b/ssh/ssh_api.c index 72172a5..1dd7d3b 100644 --- a/ssh/ssh_api.c +++ b/ssh/ssh_api.c @@ -197,10 +197,10 @@ ssh_packet_next(struct ssh *ssh, u_char *typep) } } -void * -ssh_packet_payload(struct ssh *ssh, size_t *len) +u_char * +ssh_packet_payload(struct ssh *ssh, size_t *lenp) { - return (ssh_packet_get_raw(ssh, (u_int *)len)); + return sshpkt_ptr(ssh, lenp); } int diff --git a/ssh/ssh_api.h b/ssh/ssh_api.h index 0f81364..9e69fe1 100644 --- a/ssh/ssh_api.h +++ b/ssh/ssh_api.h @@ -70,7 +70,7 @@ int ssh_packet_next(struct ssh *ssh, u_char *typep); * the current input packet and the length of this payload. * the payload is accessible until ssh_packet_next() is called again. */ -void *ssh_packet_payload(struct ssh *ssh, size_t *len); +u_char *ssh_packet_payload(struct ssh *ssh, size_t *lenp); /* * ssh_packet_put() creates an encrypted packet with the given type diff --git a/unittests/kex/test_kex.c b/unittests/kex/test_kex.c index 8ff1f3b..11e5b72 100644 --- a/unittests/kex/test_kex.c +++ b/unittests/kex/test_kex.c @@ -26,7 +26,7 @@ static int do_send_and_receive(struct ssh *from, struct ssh *to) { u_char type; - u_int len; + size_t len; char *buf; int r; @@ -37,9 +37,9 @@ do_send_and_receive(struct ssh *from, struct ssh *to) } if (type != 0) return 0; - buf = ssh_output_ptr(from, (u_int *)&len); + buf = ssh_output_ptr(from, &len); if (do_debug) - printf("%u", len); + printf("%zu", len); if (len == 0) return 0; if ((r = ssh_output_consume(from, len)) != 0 ||