mirror of
https://github.com/openbsd/src.git
synced 2026-06-18 07:13:36 +02:00
relayd: use ibuf_get_string() and ibuf_get_data() to read imsg payloads
Drop the local get_string() and read variable-length string and binary payloads through the ibuf getters instead of the raw imsg->data pointer. ibuf_get_string() no longer trims the input at the first non-printable byte like the old get_string() did; the payloads come from the parent over privsep imsg. idea and ok claudio
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: config.c,v 1.52 2026/06/14 08:48:04 rsadowski Exp $ */
|
||||
/* $OpenBSD: config.c,v 1.53 2026/06/14 08:54:21 rsadowski Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011 - 2014 Reyk Floeter <reyk@openbsd.org>
|
||||
@@ -361,8 +361,8 @@ config_gettable(struct relayd *env, struct imsg *imsg)
|
||||
return (-1);
|
||||
}
|
||||
if ((sb = ibuf_size(&ibuf)) > 0) {
|
||||
if ((tb->sendbuf = get_string(ibuf_data(&ibuf), sb)) == NULL) {
|
||||
log_warn("%s: get_string", __func__);
|
||||
if ((tb->sendbuf = ibuf_get_string(&ibuf, sb)) == NULL) {
|
||||
log_warn("%s: ibuf_get_string", __func__);
|
||||
free(tb);
|
||||
return (-1);
|
||||
}
|
||||
@@ -732,9 +732,9 @@ config_getproto(struct relayd *env, struct imsg *imsg)
|
||||
}
|
||||
if ((s = ibuf_size(&ibuf)) > 0) {
|
||||
proto->style = NULL;
|
||||
if ((proto->style = get_string(ibuf_data(&ibuf), s - 1))
|
||||
if ((proto->style = ibuf_get_string(&ibuf, s - 1))
|
||||
== NULL) {
|
||||
log_warn("%s: get_string", __func__);
|
||||
log_warn("%s: ibuf_get_string", __func__);
|
||||
free(proto);
|
||||
return (-1);
|
||||
}
|
||||
@@ -790,11 +790,7 @@ config_getrule(struct relayd *env, struct imsg *imsg)
|
||||
/* Also accept "empty" 0-length strings */ \
|
||||
if (ibuf_size(&ibuf) < (size_t)len || \
|
||||
(rule->rule_kv[_n].kv_##_f = \
|
||||
get_string(ibuf_data(&ibuf), len)) == NULL) { \
|
||||
free(rule); \
|
||||
return (-1); \
|
||||
} \
|
||||
if (len > 0 && ibuf_skip(&ibuf, len) == -1) { \
|
||||
ibuf_get_string(&ibuf, len)) == NULL) { \
|
||||
free(rule); \
|
||||
return (-1); \
|
||||
} \
|
||||
@@ -1104,8 +1100,7 @@ config_getrelay(struct relayd *env, struct imsg *imsg)
|
||||
goto fail;
|
||||
}
|
||||
if (s > 0) {
|
||||
if ((rlay->rl_tls_cakey = get_data(ibuf_data(&ibuf), s))
|
||||
== NULL)
|
||||
if ((rlay->rl_tls_cakey = get_data(&ibuf, s)) == NULL)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
+11
-18
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: relayd.c,v 1.200 2026/06/14 08:51:11 rsadowski Exp $ */
|
||||
/* $OpenBSD: relayd.c,v 1.201 2026/06/14 08:54:21 rsadowski Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 - 2016 Reyk Floeter <reyk@openbsd.org>
|
||||
@@ -437,8 +437,8 @@ parent_dispatch_pfe(int fd, struct privsep_proc *p, struct imsg *imsg)
|
||||
case IMSG_CTL_RELOAD:
|
||||
if (imsg_get_ibuf(imsg, &ibuf) != -1 &&
|
||||
(s = ibuf_size(&ibuf)) > 0) {
|
||||
if ((str = get_string(ibuf_data(&ibuf), s)) == NULL) {
|
||||
log_warn("%s: get_string", __func__);
|
||||
if ((str = ibuf_get_string(&ibuf, s)) == NULL) {
|
||||
log_warn("%s: ibuf_get_string", __func__);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
@@ -1787,28 +1787,21 @@ socket_rlimit(int maxfd)
|
||||
fatal("%s: failed to set resource limit", __func__);
|
||||
}
|
||||
|
||||
char *
|
||||
get_string(u_int8_t *ptr, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (!(isprint((unsigned char)ptr[i]) ||
|
||||
isspace((unsigned char)ptr[i])))
|
||||
break;
|
||||
|
||||
return strndup(ptr, i);
|
||||
}
|
||||
|
||||
void *
|
||||
get_data(u_int8_t *ptr, size_t len)
|
||||
get_data(struct ibuf *ibuf, size_t len)
|
||||
{
|
||||
u_int8_t *data;
|
||||
|
||||
if (len == 0)
|
||||
return (NULL);
|
||||
|
||||
if ((data = malloc(len)) == NULL)
|
||||
return (NULL);
|
||||
memcpy(data, ptr, len);
|
||||
|
||||
if (ibuf_get(ibuf, data, len) == -1) {
|
||||
free(data);
|
||||
return (NULL);
|
||||
}
|
||||
return (data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: relayd.h,v 1.284 2026/06/14 08:52:16 rsadowski Exp $ */
|
||||
/* $OpenBSD: relayd.h,v 1.285 2026/06/14 08:54:21 rsadowski Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org>
|
||||
@@ -1336,8 +1336,7 @@ void imsg_event_add(struct imsgev *);
|
||||
int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t,
|
||||
pid_t, int, void *, u_int16_t);
|
||||
void socket_rlimit(int);
|
||||
char *get_string(u_int8_t *, size_t);
|
||||
void *get_data(u_int8_t *, size_t);
|
||||
void *get_data(struct ibuf *, size_t);
|
||||
int sockaddr_cmp(struct sockaddr *, struct sockaddr *, int);
|
||||
struct in6_addr *prefixlen2mask6(u_int8_t, u_int32_t *);
|
||||
u_int32_t prefixlen2mask(u_int8_t);
|
||||
|
||||
Reference in New Issue
Block a user