summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2013-06-03 15:50:04 +0000
committereric <eric@openbsd.org>2013-06-03 15:50:04 +0000
commitc89b4b77ec01c46dfa4c8dc6d49ffaa5fe62b26e (patch)
tree2c1195b8d824c6f99735b83d03a6d5d128fd438e
parentremove dead makefile (diff)
downloadwireguard-openbsd-c89b4b77ec01c46dfa4c8dc6d49ffaa5fe62b26e.tar.xz
wireguard-openbsd-c89b4b77ec01c46dfa4c8dc6d49ffaa5fe62b26e.zip
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@
-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 *