From 1cd87e61dd3f02db2517d879eb16dc8b74c69082 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 27 Dec 2018 15:04:59 +0000 Subject: [PATCH] table_fetch() always expect a valid dst pointer. ok gilles@ --- usr.sbin/smtpd/table.c | 13 +++++-------- usr.sbin/smtpd/table_db.c | 10 ++++------ usr.sbin/smtpd/table_static.c | 7 ++----- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c index f43e52973ea..397d850ee9a 100644 --- a/usr.sbin/smtpd/table.c +++ b/usr.sbin/smtpd/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.42 2018/12/27 14:23:41 eric Exp $ */ +/* $OpenBSD: table.c,v 1.43 2018/12/27 15:04:59 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -174,18 +174,15 @@ table_fetch(struct table *table, enum table_service kind, union lookup *lk) if (table->t_backend->fetch == NULL) return (-1); - r = table->t_backend->fetch(table, kind, lk ? &buf : NULL); + r = table->t_backend->fetch(table, kind, &buf); if (r == 1) { - log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %s%s%s", + log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> \"%s\"", table_service_name(kind), table->t_backend->name, table->t_name, - lk ? "\"" : "", - (lk) ? buf : "found", - lk ? "\"" : ""); - if (buf) - r = table_parse_lookup(kind, NULL, buf, lk); + buf); + r = table_parse_lookup(kind, NULL, buf, lk); } else log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %d", diff --git a/usr.sbin/smtpd/table_db.c b/usr.sbin/smtpd/table_db.c index fde3983eb3d..426d0f7cf90 100644 --- a/usr.sbin/smtpd/table_db.c +++ b/usr.sbin/smtpd/table_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_db.c,v 1.19 2018/12/27 14:41:45 eric Exp $ */ +/* $OpenBSD: table_db.c,v 1.20 2018/12/27 15:04:59 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade @@ -221,11 +221,9 @@ table_db_fetch(struct table *table, enum table_service service, char **dst) return 0; } - if (dst) { - *dst = strdup(dbk.data); - if (*dst == NULL) - return -1; - } + *dst = strdup(dbk.data); + if (*dst == NULL) + return -1; return 1; } diff --git a/usr.sbin/smtpd/table_static.c b/usr.sbin/smtpd/table_static.c index c0d122fe1f6..361be8f4834 100644 --- a/usr.sbin/smtpd/table_static.c +++ b/usr.sbin/smtpd/table_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_static.c,v 1.28 2018/12/27 14:23:41 eric Exp $ */ +/* $OpenBSD: table_static.c,v 1.29 2018/12/27 15:04:59 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -307,7 +307,7 @@ table_static_lookup(struct table *m, enum table_service service, const char *key static int table_static_fetch(struct table *t, enum table_service service, char **dst) { - const char *k; + const char *k; if (!dict_iter(&t->t_dict, &t->t_iter, &k, (void **)NULL)) { t->t_iter = NULL; @@ -315,9 +315,6 @@ table_static_fetch(struct table *t, enum table_service service, char **dst) return 0; } - if (dst == NULL) - return 1; - *dst = strdup(k); if (*dst == NULL) return -1; -- 2.20.1