[openssh-commits] [openssh] 01/04: upstream: Add sshbuf_consume_upto_child(), to similify particular

git+noreply at mindrot.org git+noreply at mindrot.org
Tue Dec 30 11:37:51 AEDT 2025


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 55b6b1697433eca98052f5c45281133ca793a9c8
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Mon Dec 29 23:52:09 2025 +0000

    upstream: Add sshbuf_consume_upto_child(), to similify particular
    
    parsing patterns using parent/child buffer; ok markus@
    
    OpenBSD-Commit-ID: c11ed27907751f2a16c1283313e77f88617e4852
---
 sshbuf.c | 22 +++++++++++++++++++++-
 sshbuf.h | 20 +++++++++++++++++++-
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/sshbuf.c b/sshbuf.c
index 1b714e5f9..0dc411c51 100644
--- a/sshbuf.c
+++ b/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));
+}
diff --git a/sshbuf.h b/sshbuf.h
index 8c18ded02..052b08798 100644
--- a/sshbuf.h
+++ b/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);

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list