protect sshbuf_from[bs] children by refusing modification of the parent buffers

This adds a reference mechanism to struct sshbuf, making parent buffers to
those created with buffer_froms() and buffer_fromb() read-only until the
child buffer is freed. It also delays freeing of the parent buffer until
all child buffers have freed.
This commit is contained in:
Damien Miller
2012-10-09 14:33:17 +11:00
committed by Markus Friedl
parent fa6c75e284
commit 8f73555808
6 changed files with 127 additions and 30 deletions

View File

@@ -368,8 +368,9 @@ sshbuf_froms(struct sshbuf *buf, struct sshbuf **bufp)
return r;
if ((ret = sshbuf_from(p, len)) == NULL)
return SSH_ERR_ALLOC_FAIL;
if ((r = sshbuf_consume(buf, len + 4)) != 0) { /* Shouldn't happen */
free(ret);
if ((r = sshbuf_consume(buf, len + 4)) != 0 || /* Shouldn't happen */
(r = sshbuf_set_parent(ret, buf)) != 0) {
sshbuf_free(ret);
return r;
}
*bufp = ret;