summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/map_db.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/smtpd/map_db.c')
-rw-r--r--usr.sbin/smtpd/map_db.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/usr.sbin/smtpd/map_db.c b/usr.sbin/smtpd/map_db.c
index 3f77c277e9e..43a2dd573d9 100644
--- a/usr.sbin/smtpd/map_db.c
+++ b/usr.sbin/smtpd/map_db.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map_db.c,v 1.9 2012/09/21 16:40:20 eric Exp $ */
+/* $OpenBSD: map_db.c,v 1.10 2012/09/27 17:58:56 chl Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -123,10 +123,7 @@ map_db_compare(void *hdl, const char *key, enum map_kind kind,
for (r = db->seq(db, &dbk, &dbd, R_FIRST); !r;
r = db->seq(db, &dbk, &dbd, R_NEXT)) {
- buf = calloc(dbk.size+1, 1);
- if (buf == NULL)
- fatalx("calloc");
- strlcpy(buf, dbk.data, dbk.size+1);
+ buf = xmemdup(dbk.data, dbk.size + 1, "map_db_compare");
log_debug("key: %s, buf: %s", key, buf);
if (func(key, buf))
ret = 1;
@@ -144,7 +141,6 @@ map_db_get_entry(void *hdl, const char *key, size_t *len)
DBT dbk;
DBT dbv;
DB *db = hdl;
- char *result = NULL;
char pkey[MAX_LINE_SIZE];
/* workaround the stupidity of the DB interface */
@@ -156,14 +152,9 @@ map_db_get_entry(void *hdl, const char *key, size_t *len)
if ((ret = db->get(db, &dbk, &dbv, 0)) != 0)
return NULL;
- result = calloc(dbv.size, 1);
- if (result == NULL)
- fatal("calloc");
- (void)strlcpy(result, dbv.data, dbv.size);
-
*len = dbv.size;
- return result;
+ return xmemdup(dbv.data, dbv.size, "map_db_get_entry");
}
static void *
@@ -188,9 +179,8 @@ map_db_credentials(const char *key, char *line, size_t len)
return NULL;
*p++ = '\0';
- map_credentials = calloc(1, sizeof(struct map_credentials));
- if (map_credentials == NULL)
- fatalx("calloc");
+ map_credentials = xcalloc(1, sizeof *map_credentials,
+ "map_db_credentials");
if (strlcpy(map_credentials->username, line,
sizeof(map_credentials->username)) >=
@@ -217,9 +207,7 @@ map_db_alias(const char *key, char *line, size_t len)
struct map_alias *map_alias = NULL;
struct expandnode xn;
- map_alias = calloc(1, sizeof(struct map_alias));
- if (map_alias == NULL)
- fatalx("calloc");
+ map_alias = xcalloc(1, sizeof *map_alias, "map_db_alias");
while ((subrcpt = strsep(&line, ",")) != NULL) {
/* subrcpt: strip initial whitespace. */
@@ -256,9 +244,7 @@ map_db_virtual(const char *key, char *line, size_t len)
struct map_virtual *map_virtual = NULL;
struct expandnode xn;
- map_virtual = calloc(1, sizeof(struct map_virtual));
- if (map_virtual == NULL)
- fatalx("calloc");
+ map_virtual = xcalloc(1, sizeof *map_virtual, "map_db_virtual");
/* domain key, discard value */
if (strchr(key, '@') == NULL)
@@ -297,9 +283,7 @@ map_db_netaddr(const char *key, char *line, size_t len)
{
struct map_netaddr *map_netaddr = NULL;
- map_netaddr = calloc(1, sizeof(struct map_netaddr));
- if (map_netaddr == NULL)
- fatalx("calloc");
+ map_netaddr = xcalloc(1, sizeof *map_netaddr, "map_db_netaddr");
if (! text_to_netaddr(&map_netaddr->netaddr, line))
goto error;