Skip to contentSkip to conversation

common: Fix parsing SS control string

PATCH In review Lucas De Marchi 2 participants 3 messages May 22, 2013 – May 23, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: Fix parsing SS control string

It's not possible to be both greater than '9' and less than '0'. This would lead to accepting things like "#$33#" as activation and "*$33#" as deactivation, even though the string makes no sense.

---
 src/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/common.c +1 -1
index 94d70dd..17d1d58 100644
@@ -554,7 +554,7 @@ gboolean parse_ss_control_string(char *str, int *ss_type,
 
 	cur = 1;
 
-	if (str[1] != '*' && str[1] != '#' && str[1] > '9' && str[1] < '0')
+	if (str[1] != '*' && str[1] != '#' && (str[1] > '9' || str[1] < '0'))
 		goto out;
 
 	if (str[0] == '#' && str[1] == '*')
Signature · 1 line
1.8.2.3
#1 lore raw
Quoted 12 lines · Lucas De Marchi

It's not possible to be both greater than '9' and less than '0'. This would lead to accepting things like "#$33#" as activation and "*$33#" as deactivation, even though the string makes no sense.

---
 src/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/common.c +0 -0
index 94d70dd..17d1d58 100644

src/common.c gboolean parse_ss_control_string(char *str, int *ss_type, · line 558

Quoted 6 lines
src/common.c +1 -1
@@ -554,7 +554,7 @@ gboolean parse_ss_control_string(char *str, int *ss_type,
 
        cur = 1;
 
-       if (str[1] != '*' && str[1] != '#' && str[1] > '9' && str[1] < '0')
+       if (str[1] != '*' && str[1] != '#' && (str[1] > '9' || str[1] < '0'))
                goto out;

this is actually caught later in the function:

for (i = 0; i < strlen(*sc); i++)

        if (!g_ascii_isdigit((*sc)[i]))
                goto out;

But fixing the check would be good.

Lucas De Marchi

#2 lore raw
In reply to Lucas De Marchi

Hi Lucas,

Quoted 12 lines · Lucas De Marchi

It's not possible to be both greater than '9' and less than '0'. This would lead to accepting things like "#$33#" as activation and "*$33#" as deactivation, even though the string makes no sense.

---
  src/common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
src/common.c +0 -0
index 94d70dd..17d1d58 100644

src/common.c gboolean parse_ss_control_string(char *str, int *ss_type, · line 557

Quoted 5 lines
src/common.c +1 -1
@@ -554,7 +554,7 @@ gboolean parse_ss_control_string(char *str, int *ss_type,
 
  	cur = 1;
 
-	if (str[1] != '*' && str[1] != '#' && str[1] > '9' && str[1] < '0')
+	if (str[1] != '*' && str[1] != '#' && (str[1] > '9' || str[1] < '0'))

Funny how it is hiding in plain sight and nobody has found it in over 4 years. And I think you just got an award for finding the oldest bug :P

Patch has been applied, thanks.

src/common.c gboolean parse_ss_control_string(char *str, int *ss_type, · line 560

Quoted 4 lines
src/common.c +0 -0
  		goto out;
 
  	if (str[0] == '#' && str[1] == '*')

Regards,
-Denis