mirror of
https://github.com/openssh/openssh-portable.git
synced 2026-01-12 00:04:08 +08:00
upstream: Add sshbuf_consume_upto_child(), to similify particular
parsing patterns using parent/child buffer; ok markus@ OpenBSD-Commit-ID: c11ed27907751f2a16c1283313e77f88617e4852
This commit is contained in:
committed by
Damien Miller
parent
6eafc52a41
commit
55b6b16974
22
sshbuf.c
22
sshbuf.c
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: sshbuf.c,v 1.23 2024/08/14 15:42:18 tobias Exp $ */
|
||||
/* $OpenBSD: sshbuf.c,v 1.24 2025/12/29 23:52:09 djm Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2011 Damien Miller
|
||||
*
|
||||
@@ -425,3 +425,23 @@ sshbuf_consume_end(struct sshbuf *buf, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sshbuf_consume_upto_child(struct sshbuf *buf, const struct sshbuf *child)
|
||||
{
|
||||
int r;
|
||||
|
||||
if ((r = sshbuf_check_sanity(buf)) != 0 ||
|
||||
(r = sshbuf_check_sanity(child)) != 0)
|
||||
return r;
|
||||
/* This function is only used for parent/child buffers */
|
||||
if (child->parent != buf)
|
||||
return SSH_ERR_INVALID_ARGUMENT;
|
||||
/* Nonsensical if the parent has advanced past the child */
|
||||
if (sshbuf_len(child) > sshbuf_len(buf))
|
||||
return SSH_ERR_INVALID_ARGUMENT;
|
||||
/* More paranoia, shouldn't happen */
|
||||
if (child->cd < buf->cd)
|
||||
return SSH_ERR_INTERNAL_ERROR;
|
||||
/* Advance */
|
||||
return sshbuf_consume(buf, sshbuf_len(buf) - sshbuf_len(child));
|
||||
}
|
||||
|
||||
20
sshbuf.h
20
sshbuf.h
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: sshbuf.h,v 1.33 2025/11/21 01:29:06 djm Exp $ */
|
||||
/* $OpenBSD: sshbuf.h,v 1.34 2025/12/29 23:52:09 djm Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2011 Damien Miller
|
||||
*
|
||||
@@ -143,6 +143,24 @@ int sshbuf_consume(struct sshbuf *buf, size_t len);
|
||||
*/
|
||||
int sshbuf_consume_end(struct sshbuf *buf, size_t len);
|
||||
|
||||
/*
|
||||
* Consume data from a parent buffer up to that of a child buffer (i.e.
|
||||
* one created by sshbuf_fromb()).
|
||||
*
|
||||
* Intended to be used in a pattern like:
|
||||
*
|
||||
* b = sshbuf_fromb(parent);
|
||||
* sshbuf_get_string(b, &foo, &foostr);
|
||||
* sshbuf_get_u32(b, &bar);
|
||||
* sshbuf_consume_upto_child(parent, b);
|
||||
*
|
||||
* After which, both "b" and "parent" will point to the same data.
|
||||
*
|
||||
* "child" must be a direct child of "buf" (i.e. neither an unrelated buffer
|
||||
* nor a grandchild) which has consumed data past that of "buf".
|
||||
*/
|
||||
int sshbuf_consume_upto_child(struct sshbuf *buf, const struct sshbuf *child);
|
||||
|
||||
/* Extract or deposit some bytes */
|
||||
int sshbuf_get(struct sshbuf *buf, void *v, size_t len);
|
||||
int sshbuf_put(struct sshbuf *buf, const void *v, size_t len);
|
||||
|
||||
Reference in New Issue
Block a user