aboutsummaryrefslogtreecommitdiff
path: root/sshbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshbuf.c')
-rw-r--r--sshbuf.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sshbuf.c b/sshbuf.c
index 1b714e5f9c79..0dc411c51374 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));
+}