summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-08-20 18:18:17 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-08-20 18:18:17 +0000
commit0363e76fca88c7afec52ccc92b95aa7104315ea3 (patch)
tree9f5338bef1cbccc8df324b594b263bb7b5673dfd /usr.sbin
parentc512cdc0a183be6870310ed47f0cf68659524433 (diff)
Do not send more bytes than necessary with IMSG_STAT_*. The INCREMENT
and DECREMENT messages just contain the key with the ending zero. For IMSG_STAT_SET, the value is found at the beginning of the message, and the rest is the key. ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/control.c9
-rw-r--r--usr.sbin/smtpd/stat_backend.c27
2 files changed, 23 insertions, 13 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index 969a437e7cb..cf7ba541262 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.68 2012/08/18 18:18:23 gilles Exp $ */
+/* $OpenBSD: control.c,v 1.69 2012/08/20 18:18:16 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -71,7 +71,7 @@ control_imsg(struct imsgev *iev, struct imsg *imsg)
{
struct ctl_conn *c;
char *key;
- struct stat_kv *stat_kv;
+ size_t val;
log_imsg(PROC_CONTROL, iev->proc, imsg);
@@ -99,9 +99,10 @@ control_imsg(struct imsgev *iev, struct imsg *imsg)
stat_backend->decrement(key);
return;
case IMSG_STAT_SET:
- stat_kv = (struct stat_kv *)imsg->data;
+ memmove(&val, imsg->data, sizeof (val));
+ key = (char*)imsg->data + sizeof (val);
if (stat_backend)
- stat_backend->set(stat_kv->key, stat_kv->val);
+ stat_backend->set(key, val);
return;
}
diff --git a/usr.sbin/smtpd/stat_backend.c b/usr.sbin/smtpd/stat_backend.c
index b77ce3abc83..7e71ecb4b87 100644
--- a/usr.sbin/smtpd/stat_backend.c
+++ b/usr.sbin/smtpd/stat_backend.c
@@ -47,36 +47,45 @@ void
stat_increment(const char *name)
{
char key[STAT_KEY_SIZE];
+ size_t len;
- if (strlcpy(key, name, sizeof key) >= sizeof key)
+ if ((len = strlcpy(key, name, sizeof key)) >= sizeof key) {
+ len = sizeof(key) - 1;
log_warn("stat_increment: truncated key '%s', ignored", name);
+ }
imsg_compose_event(env->sc_ievs[PROC_CONTROL],
- IMSG_STAT_INCREMENT, 0, 0, -1, key, sizeof key);
+ IMSG_STAT_INCREMENT, 0, 0, -1, key, len + 1);
}
void
stat_decrement(const char *name)
{
char key[STAT_KEY_SIZE];
+ size_t len;
- if (strlcpy(key, name, sizeof key) >= sizeof key)
+ if ((len = strlcpy(key, name, sizeof key)) >= sizeof key) {
+ len = sizeof(key) - 1;
log_warn("stat_increment: truncated key '%s', ignored", name);
+ }
imsg_compose_event(env->sc_ievs[PROC_CONTROL],
- IMSG_STAT_DECREMENT, 0, 0, -1, key, sizeof key);
+ IMSG_STAT_DECREMENT, 0, 0, -1, key, len + 1);
}
void
stat_set(const char *name, size_t value)
{
- struct stat_kv kv;
+ char *s, buf[STAT_KEY_SIZE + sizeof (value)];
+ size_t len;
- bzero(&kv, sizeof kv);
- if (strlcpy(kv.key, name, sizeof kv.key) >= sizeof kv.key)
+ memmove(buf, &value, sizeof value);
+ s = buf + sizeof value;
+ if ((len = strlcpy(s, name, STAT_KEY_SIZE)) >= STAT_KEY_SIZE) {
+ len = STAT_KEY_SIZE - 1;
log_warn("stat_increment: truncated key '%s', ignored", name);
- kv.val = value;
+ }
imsg_compose_event(env->sc_ievs[PROC_CONTROL],
- IMSG_STAT_SET, 0, 0, -1, &kv, sizeof kv);
+ IMSG_STAT_SET, 0, 0, -1, buf, sizeof (value) + len + 1);
}