diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2017-01-31 12:29:48 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2017-01-31 12:29:48 +0000 |
commit | ab4ec008e7abd1c8098428dbf9642c3685383045 (patch) | |
tree | feb16b3395021bd0f5667967c25f2bb77f8b691e /sshbuf-misc.c | |
parent | 8f8c559269bccf737d318b89630a0ef812865b99 (diff) | |
download | src-test2-ab4ec008e7abd1c8098428dbf9642c3685383045.tar.gz src-test2-ab4ec008e7abd1c8098428dbf9642c3685383045.zip |
Notes
Diffstat (limited to 'sshbuf-misc.c')
-rw-r--r-- | sshbuf-misc.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sshbuf-misc.c b/sshbuf-misc.c index 3da4b80e7658..15dcfbc79196 100644 --- a/sshbuf-misc.c +++ b/sshbuf-misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshbuf-misc.c,v 1.5 2015/10/05 17:11:21 djm Exp $ */ +/* $OpenBSD: sshbuf-misc.c,v 1.6 2016/05/02 08:49:03 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -136,3 +136,26 @@ sshbuf_b64tod(struct sshbuf *buf, const char *b64) return 0; } +char * +sshbuf_dup_string(struct sshbuf *buf) +{ + const u_char *p = NULL, *s = sshbuf_ptr(buf); + size_t l = sshbuf_len(buf); + char *r; + + if (s == NULL || l > SIZE_MAX) + return NULL; + /* accept a nul only as the last character in the buffer */ + if (l > 0 && (p = memchr(s, '\0', l)) != NULL) { + if (p != s + l - 1) + return NULL; + l--; /* the nul is put back below */ + } + if ((r = malloc(l + 1)) == NULL) + return NULL; + if (l > 0) + memcpy(r, s, l); + r[l] = '\0'; + return r; +} + |