From 6cbcc73a79a0eea92fd18f2ee1bff819b28123c4 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Mon, 28 Mar 2016 21:19:39 -0400 Subject: chanopt: Ensure values are 0-2 If chanopt was set to any other value it would overwrite other values in the plugin API for channel flags. --- src/common/chanopt.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/common') diff --git a/src/common/chanopt.c b/src/common/chanopt.c index 7bd66b4a..cfa41ba1 100644 --- a/src/common/chanopt.c +++ b/src/common/chanopt.c @@ -79,11 +79,24 @@ chanopt_value (guint8 val) return "OFF"; case SET_ON: return "ON"; - default: + case SET_DEFAULT: return "{unset}"; + default: + g_assert_not_reached (); } } +static guint8 +str_to_chanopt (const char *str) +{ + if (!g_ascii_strcasecmp (str, "ON") || !strcmp (str, "1")) + return SET_ON; + else if (!g_ascii_strcasecmp (str, "OFF") || !strcmp (str, "0")) + return SET_OFF; + else + return SET_DEFAULT; +} + /* handle the /CHANOPT command */ int @@ -106,14 +119,7 @@ chanopt_command (session *sess, char *tbuf, char *word[], char *word_eol[]) if (word[offset][0]) { - if (!g_ascii_strcasecmp (word[offset], "ON")) - newval = 1; - else if (!g_ascii_strcasecmp (word[offset], "OFF")) - newval = 0; - else if (word[offset][0] == 'u') - newval = SET_DEFAULT; - else - newval = atoi (word[offset]); + newval = str_to_chanopt (word[offset]); } if (!quiet) @@ -281,7 +287,7 @@ chanopt_load_all (void) else { if (current) - chanopt_add_opt (current, buf, atoi (eq + 2)); + chanopt_add_opt (current, buf, str_to_chanopt (eq + 2)); } } -- cgit 1.4.1