[Mp3blaster-devel] [patch] mp3blaster: accepts invalid values for yesno configs

Bernhard Fischer rep.nop at aon.at
Sun Jan 9 19:04:30 CET 2005


Package: mp3blaster
Version: 1:3.2.0-6
Severity: minor
Tags: patch

cf_type_yesno() did not reject improper settings for yes/no options
in the configuration file as opposed to what all other cf_type..()
checks do.

Attached patch corrects the check whether the given value is valid or
not.

To reproduce, put an arbitrary string as value for a type_yesno into
your mp3blasterrc, where only yes/true/1 resp. no/false/0 are allowed:
DownFrequency = thisshouldret-1andnot0


src/config.cc
	* catch invalid yesno values in configfile.


-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-p4-smp
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages mp3blaster depends on:
ii  libc6                       2.3.2.ds1-20 GNU C Library: Shared libraries an
ii  libgcc1                     1:3.4.3-6    GCC support library
ii  libncurses5                 5.4-4        Shared libraries for terminal hand
ii  libsidplay1-c102            1.36.59-2    SID (MOS 6581) emulation library
ii  libstdc++5                  1:3.3.5-5    The GNU Standard C++ Library v3
ii  libvorbis0a                 1.0.1-1      The Vorbis General Audio Compressi
ii  libvorbisfile3              1.0.1-1      The Vorbis General Audio Compressi

-- no debconf information
-------------- next part --------------
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/src/config.cc mp3blaster-3.2.0/src/config.cc
--- mp3blaster-3.2.0.oorig/src/config.cc	2002-09-20 22:40:15.000000000 +0200
+++ mp3blaster-3.2.0/src/config.cc	2005-01-09 18:34:50.000000000 +0100
@@ -190,6 +194,17 @@ char errstring[256];
 
 extern struct _globalopts globalopts; /* from main.cc */
 
+int
+cf_type_number(const char *string, int *succeed=0)
+{
+	int tmp;
+	if ((!sscanf(string, "%d", &tmp) || tmp != atoi(string)) && succeed)
+		*succeed = 0;
+	else if (succeed)
+		*succeed = 1;
+	return tmp;
+}
+
 /* returns 1 if string == yes|true|1 (case-insensitive)
  * returns 0 if string == no|false|0 (case-insensitive)
  * returns -1 in all other cases.
@@ -197,26 +212,20 @@ extern struct _globalopts globalopts; /*
 short
 cf_type_yesno(const char *string)
 {
+	int _tmp, _nr;
+	_nr = cf_type_number(string, &_tmp);
+	if (!_tmp) {
+		_nr = -1;
+	}
 	if (!strcasecmp(string, "yes") || !strcasecmp(string, "true") ||
-		atoi(string) == 1)
+		_nr == 1)
 		return 1;
 	if (!strcasecmp(string, "no") || !strcasecmp(string, "false") ||
-		atoi(string) == 0)
+		_nr == 0)
 		return 0;
 	return -1;
 }
 
-int
-cf_type_number(const char *string, int *succeed=0)
-{
-	int tmp;
-	if ((!sscanf(string, "%d", &tmp) || tmp != atoi(string)) && succeed)
-		*succeed = 0;
-	else if (succeed)
-		*succeed = 1;
-	return tmp;	
-}
-
 /*if string consists of one char (strlen==1), return the char cast to int.
  * else, return ERR
  */



More information about the Mp3blaster-devel mailing list