From patchwork Thu Aug 14 07:11:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Erlbeck X-Patchwork-Id: 379834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D7722140081 for ; Thu, 14 Aug 2014 17:12:58 +1000 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1XHpDG-0002zz-4z; Thu, 14 Aug 2014 09:12:42 +0200 Received: from mail.sysmocom.de ([144.76.43.93]) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1XHpBs-0002zt-1Y for openbsc@lists.osmocom.org; Thu, 14 Aug 2014 09:11:17 +0200 Received: from sysmocom-tmp.am93.sysmocom.de (91-65-194-134-dynip.superkabel.de [91.65.194.134]) by mail.sysmocom.de (Postfix) with ESMTPSA id BD6AC65176; Thu, 14 Aug 2014 07:11:13 +0000 (UTC) From: Jacob Erlbeck To: openbsc@lists.osmocom.org Subject: [PATCH] gbproxy: Add gbprox_clear_patch_filter() (Coverity) Date: Thu, 14 Aug 2014 09:11:04 +0200 Message-Id: <1408000264-9733-1-git-send-email-jerlbeck@sysmocom.de> X-Mailer: git-send-email 1.9.1 X-Spam-Score: 0.2 (/) X-Spam-Report: SpamASsassin versoin 3.3.1 on ganesha.gnumonks.org summary: Content analysis details: (0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.1 TW_GB BODY: Odd Letter Triples with GB 0.1 TW_CF BODY: Odd Letter Triples with CF Cc: Jacob Erlbeck X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openbsc-bounces@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org Add a separate function to clear the IMSI filter to be used instead of gbprox_set_patch_filter(cfg, NULL, ...). Albeit it fixes a Coverity issue (Unchecked return value), it is a false positive, since the return value is always 0 in these cases. Nevertheless it is more obvious what happens when an explicit clear function is called. Using NULL as filter argument of gbprox_set_patch_filter still clears the filter. Fixes: Coverity CID 1231255 Sponsored-by: On-Waves ehf --- openbsc/include/openbsc/gb_proxy.h | 1 + openbsc/src/gprs/gb_proxy.c | 13 +++++++++---- openbsc/src/gprs/gb_proxy_vty.c | 4 ++-- openbsc/tests/gbproxy/gbproxy_test.c | 6 ++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/openbsc/include/openbsc/gb_proxy.h b/openbsc/include/openbsc/gb_proxy.h index 039a9a1..d6dde10 100644 --- a/openbsc/include/openbsc/gb_proxy.h +++ b/openbsc/include/openbsc/gb_proxy.h @@ -115,6 +115,7 @@ void gbprox_reset(struct gbproxy_config *cfg); int gbprox_set_patch_filter(struct gbproxy_config *cfg, const char *filter, const char **err_msg); +void gbprox_clear_patch_filter(struct gbproxy_config *cfg); void gbprox_delete_tlli(struct gbproxy_peer *peer, struct gbproxy_tlli_info *tlli_info); diff --git a/openbsc/src/gprs/gb_proxy.c b/openbsc/src/gprs/gb_proxy.c index a8ce3cc..64fb55b 100644 --- a/openbsc/src/gprs/gb_proxy.c +++ b/openbsc/src/gprs/gb_proxy.c @@ -481,16 +481,21 @@ static void gbprox_delete_tllis(struct gbproxy_peer *peer) OSMO_ASSERT(llist_empty(&state->enabled_tllis)); } +void gbprox_clear_patch_filter(struct gbproxy_config *cfg) +{ + if (cfg->check_imsi) { + regfree(&cfg->imsi_re_comp); + cfg->check_imsi = 0; + } +} + int gbprox_set_patch_filter(struct gbproxy_config *cfg, const char *filter, const char **err_msg) { static char err_buf[300]; int rc; - if (cfg->check_imsi) { - regfree(&cfg->imsi_re_comp); - cfg->check_imsi = 0; - } + gbprox_clear_patch_filter(cfg); if (!filter) return 0; diff --git a/openbsc/src/gprs/gb_proxy_vty.c b/openbsc/src/gprs/gb_proxy_vty.c index ec73ae6..9574a45 100644 --- a/openbsc/src/gprs/gb_proxy_vty.c +++ b/openbsc/src/gprs/gb_proxy_vty.c @@ -193,7 +193,7 @@ static int set_core_apn(struct vty *vty, const char *apn, const char *filter) talloc_free(g_cfg->core_apn); g_cfg->core_apn = NULL; g_cfg->core_apn_size = 0; - gbprox_set_patch_filter(g_cfg, NULL, NULL); + gbprox_clear_patch_filter(g_cfg); return CMD_SUCCESS; } @@ -206,7 +206,7 @@ static int set_core_apn(struct vty *vty, const char *apn, const char *filter) } if (!filter) { - gbprox_set_patch_filter(g_cfg, NULL, NULL); + gbprox_clear_patch_filter(g_cfg); } else if (gbprox_set_patch_filter(g_cfg, filter, &err_msg) != 0) { vty_out(vty, "Match expression invalid: %s%s", err_msg, VTY_NEWLINE); diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c index 964c6da..5363749 100644 --- a/openbsc/tests/gbproxy/gbproxy_test.c +++ b/openbsc/tests/gbproxy/gbproxy_test.c @@ -1571,6 +1571,12 @@ static void test_gbproxy_imsi_matching(void) OSMO_ASSERT(gbprox_set_patch_filter(&cfg, NULL, &err_msg) == 0); OSMO_ASSERT(cfg.check_imsi == 0); + OSMO_ASSERT(gbprox_set_patch_filter(&cfg, filter_re2, &err_msg) == 0); + OSMO_ASSERT(cfg.check_imsi == 1); + + gbprox_clear_patch_filter(&cfg); + OSMO_ASSERT(cfg.check_imsi == 0); + peer = gbproxy_peer_alloc(&cfg, 20); OSMO_ASSERT(gbprox_set_patch_filter(&cfg, filter_re2, &err_msg) == 0);