Re: [PATCH v3 6/7] v4l-utils/dvb: add COUNTRY property

2014-11-02 Thread Gregor Jasny
Hello,

Hello Coverity detected that dvb_guess_user_country introduces a
resource leak (CID 1250445).

On 31/10/14 14:13, tsk...@gmail.com wrote:
 +enum dvb_country_t dvb_guess_user_country(void)
 +{
 + char * buf, * pch, * pbuf;
 + unsigned cat;
 + enum dvb_country_t id = COUNTRY_UNKNOWN;
 +
 + for (cat = 0; cat  sizeof(cats)/sizeof(cats[0]); cat++) {
 +
 + // the returned char * should be C, POSIX or something 
 valid.
 + // If valid, we can only *guess* which format is returned.
 + // Assume here something like de_DE.iso8859-1@euro or 
 de_DE.utf-8
 + buf = secure_getenv(cats[cat]);
 + if (! buf || strlen(buf)  2)
 + continue;
 +
 + buf = strdup(buf);
 + pbuf= buf;
 +
 + if (! strncmp(buf, POSIX, MIN(strlen(buf), 5)) ||
 + ! (strncmp(buf, en, MIN(strlen(buf), 2))  
 !isalpha(buf[2])) )
 + continue;
 +
 + // assuming 'language_country.encoding@variant'
 +
 + // country after '_', if given
 + if ((pch = strchr(buf, '_')))
 + pbuf = pch + 1;
 +
 + // remove all after '@', including '@'
 + if ((pch = strchr(pbuf, '@')))
 + *pch = 0;
 +
 + // remove all after '.', including '.'
 + if ((pch = strchr(pbuf, '.')))
 + *pch = 0;
 +
 + if (strlen(pbuf) == 2)
 + id = dvb_country_a2_to_id(pbuf);
 + free(buf);
 + if (id != COUNTRY_UNKNOWN)
 + return id;
 + }
 +
 + return COUNTRY_UNKNOWN;
 +}

pbuf / buf may get leaked due to the continue statement.

Could you please post a patch?

Thanks,
Gregor
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 6/7] v4l-utils/dvb: add COUNTRY property

2014-10-31 Thread tskd08
From: Akihiro Tsukada tsk...@gmail.com

to distinguish country variants of delivery systems like ISDB-T.

Signed-off-by: Akihiro Tsukada tsk...@gmail.com
---
 configure.ac  |   4 +
 lib/include/libdvbv5/countries.h  | 307 +++
 lib/include/libdvbv5/dvb-fe.h |  14 ++
 lib/include/libdvbv5/dvb-v5-std.h |   7 +-
 lib/libdvbv5/Makefile.am  |   2 +
 lib/libdvbv5/countries.c  | 427 ++
 lib/libdvbv5/dvb-fe-priv.h|   6 +-
 lib/libdvbv5/dvb-fe.c |  76 ++-
 lib/libdvbv5/dvb-file.c   |  19 ++
 lib/libdvbv5/dvb-v5-std.c |   2 +
 utils/dvb/dvbv5-scan.c|   9 +
 utils/dvb/dvbv5-zap.c |  10 +
 12 files changed, 879 insertions(+), 4 deletions(-)
 create mode 100644 lib/include/libdvbv5/countries.h
 create mode 100644 lib/libdvbv5/countries.c

diff --git a/configure.ac b/configure.ac
index 9646fe9..d44214f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,8 @@ AC_CONFIG_FILES([Makefile
utils/dvb/dvbv5-zap.1
 ])
 
+AC_GNU_SOURCE
+
 AM_INIT_AUTOMAKE([1.9 subdir-objects no-dist-gzip dist-bzip2 
-Wno-portability]) # 1.10 is needed for target_LIBTOOLFLAGS
 
 AM_MAINTAINER_MODE
@@ -80,6 +82,8 @@ gl_VISIBILITY
 AC_CHECK_HEADERS([sys/klog.h])
 AC_CHECK_FUNCS([klogctl])
 
+AC_CHECK_FUNCS([__secure_getenv secure_getenv])
+
 # Check host os
 case $host_os in
   linux*)
diff --git a/lib/include/libdvbv5/countries.h b/lib/include/libdvbv5/countries.h
new file mode 100644
index 000..0766717
--- /dev/null
+++ b/lib/include/libdvbv5/countries.h
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2006, 2007, 2008, 2009 Winfried Koehler
+ * Copyright (C) 2014 Akihiro Tsukada
+ *
+ * This program 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
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 this program. if not, see http://www.gnu.org/licenses/.
+ *
+ */
+
+/**
+ * @file countries.h
+ * @ingroup ancillary
+ * @brief Provides ancillary code to convert ISO 3166-1 country codes
+ * @copyright GNU General Public License version 2 (GPLv2)
+ * @author Winfried Koehler
+ * @author Akihiro Tsukada
+ *
+ * @par Bug Report
+ * Please submit bug reports and patches to linux-media@vger.kernel.org
+ */
+
+#ifndef _COUNTRIES_H_
+#define _COUNTRIES_H_
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+/* ISO-3166-1 alpha-2 country code */
+enum dvb_country_t {
+COUNTRY_UNKNOWN,
+
+AD,
+AE,
+AF,
+AG,
+AI,
+AL,
+AM,
+AO,
+AQ,
+AR,
+AS,
+AT,
+AU,
+AW,
+AX,
+AZ,
+BA,
+BB,
+BD,
+BE,
+BF,
+BG,
+BH,
+BI,
+BJ,
+BL,
+BM,
+BN,
+BO,
+BQ,
+BR,
+BS,
+BT,
+BV,
+BW,
+BY,
+BZ,
+CA,
+CC,
+CD,
+CF,
+CG,
+CH,
+CI,
+CK,
+CL,
+CM,
+CN,
+CO,
+CR,
+CU,
+CV,
+CW,
+CX,
+CY,
+CZ,
+DE,
+DJ,
+DK,
+DM,
+DO,
+DZ,
+EC,
+EE,
+EG,
+EH,
+ER,
+ES,
+ET,
+FI,
+FJ,
+FK,
+FM,
+FO,
+FR,
+GA,
+GB,
+GD,
+GE,
+GF,
+GG,
+GH,
+GI,
+GL,
+GM,
+GN,
+GP,
+GQ,
+GR,
+GS,
+GT,
+GU,
+GW,
+GY,
+HK,
+HM,
+HN,
+HR,
+HT,
+HU,
+ID,
+IE,
+IL,
+IM,
+IN,
+IO,
+IQ,
+IR,
+IS,
+IT,
+JE,
+JM,
+JO,
+JP,
+KE,
+KG,
+KH,
+KI,
+KM,
+KN,
+KP,
+KR,
+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