-/* $OpenBSD: sshbuf-getput-basic.c,v 1.11 2020/06/05 03:25:35 djm Exp $ */
+/* $OpenBSD: sshbuf-getput-basic.c,v 1.12 2022/05/25 00:31:13 djm Exp $ */
/*
* Copyright (c) 2011 Damien Miller
*
return r;
if (valp != NULL) {
if ((*valp = malloc(len + 1)) == NULL) {
- SSHBUF_DBG(("SSH_ERR_ALLOC_FAIL"));
+ SSHBUF_DBG("SSH_ERR_ALLOC_FAIL");
return SSH_ERR_ALLOC_FAIL;
}
if (len != 0)
*lenp = len;
if (sshbuf_consume(buf, len + 4) != 0) {
/* Shouldn't happen */
- SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR"));
+ SSHBUF_DBG("SSH_ERR_INTERNAL_ERROR");
SSHBUF_ABORT();
return SSH_ERR_INTERNAL_ERROR;
}
if (lenp != NULL)
*lenp = 0;
if (sshbuf_len(buf) < 4) {
- SSHBUF_DBG(("SSH_ERR_MESSAGE_INCOMPLETE"));
+ SSHBUF_DBG("SSH_ERR_MESSAGE_INCOMPLETE");
return SSH_ERR_MESSAGE_INCOMPLETE;
}
len = PEEK_U32(p);
if (len > SSHBUF_SIZE_MAX - 4) {
- SSHBUF_DBG(("SSH_ERR_STRING_TOO_LARGE"));
+ SSHBUF_DBG("SSH_ERR_STRING_TOO_LARGE");
return SSH_ERR_STRING_TOO_LARGE;
}
if (sshbuf_len(buf) - 4 < len) {
- SSHBUF_DBG(("SSH_ERR_MESSAGE_INCOMPLETE"));
+ SSHBUF_DBG("SSH_ERR_MESSAGE_INCOMPLETE");
return SSH_ERR_MESSAGE_INCOMPLETE;
}
if (valp != NULL)
/* Allow a \0 only at the end of the string */
if (len > 0 &&
(z = memchr(p , '\0', len)) != NULL && z < p + len - 1) {
- SSHBUF_DBG(("SSH_ERR_INVALID_FORMAT"));
+ SSHBUF_DBG("SSH_ERR_INVALID_FORMAT");
return SSH_ERR_INVALID_FORMAT;
}
if ((r = sshbuf_skip_string(buf)) != 0)
return -1;
if (valp != NULL) {
if ((*valp = malloc(len + 1)) == NULL) {
- SSHBUF_DBG(("SSH_ERR_ALLOC_FAIL"));
+ SSHBUF_DBG("SSH_ERR_ALLOC_FAIL");
return SSH_ERR_ALLOC_FAIL;
}
if (len != 0)
int r;
if (len > SSHBUF_SIZE_MAX - 4) {
- SSHBUF_DBG(("SSH_ERR_NO_BUFFER_SPACE"));
+ SSHBUF_DBG("SSH_ERR_NO_BUFFER_SPACE");
return SSH_ERR_NO_BUFFER_SPACE;
}
if ((r = sshbuf_reserve(buf, len + 4, &d)) < 0)
int r, prepend;
if (len > SSHBUF_SIZE_MAX - 5) {
- SSHBUF_DBG(("SSH_ERR_NO_BUFFER_SPACE"));
+ SSHBUF_DBG("SSH_ERR_NO_BUFFER_SPACE");
return SSH_ERR_NO_BUFFER_SPACE;
}
/* Skip leading zero bytes */
*lenp = len;
if (sshbuf_consume(buf, olen + 4) != 0) {
/* Shouldn't happen */
- SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR"));
+ SSHBUF_DBG("SSH_ERR_INTERNAL_ERROR");
SSHBUF_ABORT();
return SSH_ERR_INTERNAL_ERROR;
}
-/* $OpenBSD: sshbuf-getput-crypto.c,v 1.8 2019/11/15 06:00:20 djm Exp $ */
+/* $OpenBSD: sshbuf-getput-crypto.c,v 1.9 2022/05/25 00:31:13 djm Exp $ */
/*
* Copyright (c) 2011 Damien Miller
*
/* Skip string */
if (sshbuf_get_string_direct(buf, NULL, NULL) != 0) {
/* Shouldn't happen */
- SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR"));
+ SSHBUF_DBG("SSH_ERR_INTERNAL_ERROR");
SSHBUF_ABORT();
return SSH_ERR_INTERNAL_ERROR;
}
size_t len;
if (pt == NULL) {
- SSHBUF_DBG(("SSH_ERR_ALLOC_FAIL"));
+ SSHBUF_DBG("SSH_ERR_ALLOC_FAIL");
return SSH_ERR_ALLOC_FAIL;
}
if ((r = sshbuf_peek_string_direct(buf, &d, &len)) < 0) {
/* Skip string */
if (sshbuf_get_string_direct(buf, NULL, NULL) != 0) {
/* Shouldn't happen */
- SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR"));
+ SSHBUF_DBG("SSH_ERR_INTERNAL_ERROR");
SSHBUF_ABORT();
return SSH_ERR_INTERNAL_ERROR;
}
-/* $OpenBSD: sshbuf.c,v 1.16 2022/04/08 04:40:40 djm Exp $ */
+/* $OpenBSD: sshbuf.c,v 1.17 2022/05/25 00:31:13 djm Exp $ */
/*
* Copyright (c) 2011 Damien Miller
*
buf->size > buf->alloc ||
buf->off > buf->size)) {
/* Do not try to recover from corrupted buffer internals */
- SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR"));
+ SSHBUF_DBG("SSH_ERR_INTERNAL_ERROR");
ssh_signal(SIGSEGV, SIG_DFL);
raise(SIGSEGV);
return SSH_ERR_INTERNAL_ERROR;
static void
sshbuf_maybe_pack(struct sshbuf *buf, int force)
{
- SSHBUF_DBG(("force %d", force));
+ SSHBUF_DBG("force %d", force);
SSHBUF_TELL("pre-pack");
if (buf->off == 0 || buf->readonly || buf->refcount > 1)
return;
u_char *dp;
int r;
- SSHBUF_DBG(("set max buf = %p len = %zu", buf, max_size));
+ SSHBUF_DBG("set max buf = %p len = %zu", buf, max_size);
if ((r = sshbuf_check_sanity(buf)) != 0)
return r;
if (max_size == buf->max_size)
rlen = ROUNDUP(buf->size, SSHBUF_SIZE_INC);
if (rlen > max_size)
rlen = max_size;
- SSHBUF_DBG(("new alloc = %zu", rlen));
+ SSHBUF_DBG("new alloc = %zu", rlen);
if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL)
return SSH_ERR_ALLOC_FAIL;
buf->cd = buf->d = dp;
u_char *dp;
int r;
- SSHBUF_DBG(("allocate buf = %p len = %zu", buf, len));
+ SSHBUF_DBG("allocate buf = %p len = %zu", buf, len);
if ((r = sshbuf_check_reserve(buf, len)) != 0)
return r;
/*
*/
need = len + buf->size - buf->alloc;
rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC);
- SSHBUF_DBG(("need %zu initial rlen %zu", need, rlen));
+ SSHBUF_DBG("need %zu initial rlen %zu", need, rlen);
if (rlen > buf->max_size)
rlen = buf->alloc + need;
- SSHBUF_DBG(("adjusted rlen %zu", rlen));
+ SSHBUF_DBG("adjusted rlen %zu", rlen);
if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL) {
- SSHBUF_DBG(("realloc fail"));
+ SSHBUF_DBG("realloc fail");
return SSH_ERR_ALLOC_FAIL;
}
buf->alloc = rlen;
if (dpp != NULL)
*dpp = NULL;
- SSHBUF_DBG(("reserve buf = %p len = %zu", buf, len));
+ SSHBUF_DBG("reserve buf = %p len = %zu", buf, len);
if ((r = sshbuf_allocate(buf, len)) != 0)
return r;
{
int r;
- SSHBUF_DBG(("len = %zu", len));
+ SSHBUF_DBG("len = %zu", len);
if ((r = sshbuf_check_sanity(buf)) != 0)
return r;
if (len == 0)
{
int r;
- SSHBUF_DBG(("len = %zu", len));
+ SSHBUF_DBG("len = %zu", len);
if ((r = sshbuf_check_sanity(buf)) != 0)
return r;
if (len == 0)
-/* $OpenBSD: sshbuf.h,v 1.25 2022/01/22 00:43:43 djm Exp $ */
+/* $OpenBSD: sshbuf.h,v 1.26 2022/05/25 00:31:13 djm Exp $ */
/*
* Copyright (c) 2011 Damien Miller
*
# ifdef SSHBUF_DEBUG
# define SSHBUF_TELL(what) do { \
- printf("%s:%d %s: %s size %zu alloc %zu off %zu max %zu\n", \
+ fprintf(stderr, \
+ "%s:%d %s: %s size %zu alloc %zu off %zu max %zu\n", \
__FILE__, __LINE__, __func__, what, \
buf->size, buf->alloc, buf->off, buf->max_size); \
- fflush(stdout); \
+ fflush(stderr); \
} while (0)
-# define SSHBUF_DBG(x) do { \
- printf("%s:%d %s: ", __FILE__, __LINE__, __func__); \
- printf x; \
- printf("\n"); \
- fflush(stdout); \
+# define SSHBUF_DBG(...) do { \
+ fprintf(stderr, "%s:%d %s: ", __FILE__, __LINE__, __func__); \
+ fprintf(stderr, __VA_ARGS__); \
+ fprintf(stderr, "\n"); \
+ fflush(stderr); \
} while (0)
# else
# define SSHBUF_TELL(what)