From 38bd819ed5b2c30a9bc302412d04f9cb8d345f02 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 21 Feb 2006 15:23:11 +0000 Subject: [PATCH] Ensure zebra_start fails if bad .cfg is passed. --- index/zebraapi.c | 15 +++++++++++---- test/api/Makefile.am | 5 +++-- test/api/t0.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 test/api/t0.c diff --git a/index/zebraapi.c b/index/zebraapi.c index 8207926..dc26b11 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.201 2006-02-09 08:31:02 adam Exp $ +/* $Id: zebraapi.c,v 1.202 2006-02-21 15:23:11 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -184,11 +184,18 @@ ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res) const char *passwd_plain = 0; const char *passwd_encrypt = 0; const char *dbaccess = 0; - ZebraService zh = xmalloc(sizeof(*zh)); + ZebraService zh = 0; if (configName) - res_read_file(res, configName); - + { + ZEBRA_RES ret = res_read_file(res, configName); + if (ret != ZEBRA_OK) + { + res_close(res); + return 0; + } + } + zh = xmalloc(sizeof(*zh)); zh->global_res = res; zh->sessions = 0; diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 92a9d49..0e63ebe 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -1,9 +1,9 @@ -# $Id: Makefile.am,v 1.31 2005-12-15 13:28:46 adam Exp $ +# $Id: Makefile.am,v 1.32 2006-02-21 15:23:11 adam Exp $ noinst_PROGRAMS = testclient testclient_SOURCES = testclient.c -simpletests = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 +simpletests = t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 safaritests = safari1 check_PROGRAMS = $(simpletests) $(safaritests) TESTS = $(check_PROGRAMS) @@ -14,6 +14,7 @@ noinst_LIBRARIES = libtestlib.a libtestlib_a_SOURCES = testlib.c testlib.h +t0_SOURCES = t0.c t1_SOURCES = t1.c t2_SOURCES = t2.c t3_SOURCES = t3.c diff --git a/test/api/t0.c b/test/api/t0.c new file mode 100644 index 0000000..51c92d6 --- /dev/null +++ b/test/api/t0.c @@ -0,0 +1,38 @@ +/* $Id: t0.c,v 1.1 2006-02-21 15:23:11 adam Exp $ + Copyright (C) 1995-2005 + Index Data ApS + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ + +/** t0 - test zebra_start .. */ + +#include +#include "testlib.h" + +int main(int argc, char **argv) +{ + ZebraService zs; + + start_log(argc, argv); + + zs = zebra_start("xxxxpoiasdfasfd.cfg"); + if (zs) + exit(1); + return 0; +} -- 1.7.10.4