summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2013-06-03 15:50:05 +0000
committerEric Faurot <eric@cvs.openbsd.org>2013-06-03 15:50:05 +0000
commite31f9db8b33568c9e5f9421a9759d3c09eeb08b3 (patch)
tree5be6f2141657c02b082f197658e59dd7f2d3541f /usr.sbin
parentd2f624e3d7fff4089774b8b025e45601b7fa2623 (diff)
lowercase the key when adding an entry to a static table, since the
lookups are done on lowercase strings. warn about duplicates entries and avoid to leak memory. ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/table.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c
index 4da759384e2..0f373a272bc 100644
--- a/usr.sbin/smtpd/table.c
+++ b/usr.sbin/smtpd/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.4 2013/05/24 17:03:14 eric Exp $ */
+/* $OpenBSD: table.c,v 1.5 2013/06/03 15:50:04 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -266,9 +266,22 @@ table_config(struct table *t)
void
table_add(struct table *t, const char *key, const char *val)
{
+ char lkey[1024], *old;
+
if (t->t_type & T_DYNAMIC)
errx(1, "table_add: cannot add to table");
- dict_set(&t->t_dict, key, val ? xstrdup(val, "table_add") : NULL);
+
+ if (! lowercase(lkey, key, sizeof lkey)) {
+ log_warnx("warn: lookup key too long: %s", key);
+ return;
+ }
+
+ old = dict_set(&t->t_dict, lkey, val ? xstrdup(val, "table_add") : NULL);
+ if (old) {
+ log_warnx("warn: duplicate key \"%s\" in static table \"%s\"",
+ lkey, t->t_name);
+ free(old);
+ }
}
const void *