fixed small invalid mode bug with "-k" and a crash bug in event_neonspam_chanmsg.c
authorpk910 <philipp@zoelle1.de>
Thu, 12 Jan 2012 19:55:12 +0000 (20:55 +0100)
committerpk910 <philipp@zoelle1.de>
Thu, 12 Jan 2012 19:55:12 +0000 (20:55 +0100)
src/ModeNode.c
src/cmd_neonserv_mode.c
src/event_neonspam_chanmsg.c

index 7dc10f0b68eda98f0434c15a92623961e8581a31..c0fd065e73328b49323b6042e9fb4de71e2e3ac3 100644 (file)
@@ -284,7 +284,7 @@ int parseMode(struct ModeNode* modes, int add, char mode, char *param) {
         modes->modes &= ~modeOpt[0];
         modes->allmodes |= modeOpt[0];
         if(MODE_TYPE == CHANNEL_MODE_TYPE_B) {
-            if(!param) return 0;
+            if(!param && !(modeOpt[2] & CHANNEL_MODE_KEY)) return 0;
             if(MODE_VALUE == CHANNEL_MODE_VALUE_STRING) {
                 free(modes->mode_str_args[MODE_VALUE_INDEX]);
                 modes->mode_str_args[MODE_VALUE_INDEX] = NULL;
index 4e3ef0f5022448dad3dd6bb830c79ce3e4a9eccb..8a11e36ea1d3612cd2a9515c889b904bdb62f5f8 100644 (file)
@@ -248,6 +248,12 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
                                 }
                             }
                         }
+                    } else if(!add && (modetype & CHANNEL_MODE_TYPE) == CHANNEL_MODE_TYPE_B) {
+                        if(arg == argc && !(modetype & CHANNEL_MODE_KEY)) {
+                            reply(textclient, user, "NS_MODE_INVALID", modeStr[i]);
+                            return;
+                        }
+                        carg = (arg == argc ? NULL : argv[arg++]);
                     } else
                         carg = NULL;
                     if((modetype & CHANNEL_MODE_TYPE) == CHANNEL_MODE_TYPE_D && isModeSet(chan->modes, modeStr[i]) == add)
index 117d5ad85c96130175b1774731f71bcc20439501..c5bc02f90d52a3abecca645f6db63be8eaa95ca0 100644 (file)
@@ -162,7 +162,7 @@ static USERAUTH_CALLBACK(neonspam_event_chanmsg_nick_lookup) {
 
 static void neonspam_event_chanmsg_punish(struct ClientSocket *client, struct ChanUser *chanuser, struct NeonSpamSettings *settings, unsigned int warn, unsigned int punish) {
     MYSQL_RES *res;
-    MYSQL_ROW row;
+    MYSQL_ROW row, defaults;
     loadChannelSettings(chanuser->chan);
     int uaccess = 0;
     if(chanuser->user->flags & USERFLAG_ISAUTHED)
@@ -175,53 +175,53 @@ static void neonspam_event_chanmsg_punish(struct ClientSocket *client, struct Ch
         printf_mysql_query("SELECT `channel_spam_reaction`, `channel_spam_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id);
         res = mysql_use();
         row = mysql_fetch_row(res);
-        if(!row[0]) {
+        if(!row[0] || !row[1]) {
             printf_mysql_query("SELECT `channel_spam_reaction`, `channel_spam_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'");
             res = mysql_use();
-            row = mysql_fetch_row(res);
+            defaults = mysql_fetch_row(res);
         }
         sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_SPAM);
-        punishment = atoi(row[0]) + 1;
-        punish_time = atoi(row[1]);
+        punishment = atoi((row[0] ? row[0] : defaults[0])) + 1;
+        punish_time = atoi((row[1] ? row[1] : defaults[1]));
     }
     if(!punishment && (punish & SPAMSETTINGS_FLOODSCAN) && settings->exceptlevel[SPAMSETTINGS_FLOODEXCINDEX] > uaccess) {
         printf_mysql_query("SELECT `channel_flood_reaction`, `channel_flood_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id);
         res = mysql_use();
         row = mysql_fetch_row(res);
-        if(!row[0]) {
+        if(!row[0] || !row[1]) {
             printf_mysql_query("SELECT `channel_flood_reaction`, `channel_flood_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'");
             res = mysql_use();
-            row = mysql_fetch_row(res);
+            defaults = mysql_fetch_row(res);
         }
         sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_FLOOD);
-        punishment = atoi(row[0]) + 1;
-        punish_time = atoi(row[1]);
+        punishment = atoi((row[0] ? row[0] : defaults[0])) + 1;
+        punish_time = atoi((row[1] ? row[1] : defaults[1]));
     }
     if(!punishment && (punish & SPAMSETTINGS_CAPSSCAN) && settings->exceptlevel[SPAMSETTINGS_CAPSEXCINDEX] > uaccess) {
         printf_mysql_query("SELECT `channel_caps_reaction`, `channel_caps_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id);
         res = mysql_use();
         row = mysql_fetch_row(res);
-        if(!row[0]) {
+        if(!row[0] || !row[1]) {
             printf_mysql_query("SELECT `channel_caps_reaction`, `channel_caps_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'");
             res = mysql_use();
-            row = mysql_fetch_row(res);
+            defaults = mysql_fetch_row(res);
         }
         sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_CAPS);
-        punishment = atoi(row[0]) + 1;
-        punish_time = atoi(row[1]);
+        punishment = atoi((row[0] ? row[0] : defaults[0])) + 1;
+        punish_time = atoi((row[1] ? row[1] : defaults[1]));
     }
     if(!punishment && (punish & SPAMSETTINGS_DIGITSCAN) && settings->exceptlevel[SPAMSETTINGS_DIGITEXCINDEX] > uaccess) {
         printf_mysql_query("SELECT `channel_digit_reaction`, `channel_digit_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id);
         res = mysql_use();
         row = mysql_fetch_row(res);
-        if(!row[0]) {
+        if(!row[0] || !row[1]) {
             printf_mysql_query("SELECT `channel_digit_reaction`, `channel_digit_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'");
             res = mysql_use();
-            row = mysql_fetch_row(res);
+            defaults = mysql_fetch_row(res);
         }
         sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_DIGIT);
-        punishment = atoi(row[0]) + 1;
-        punish_time = atoi(row[1]);
+        punishment = atoi((row[0] ? row[0] : defaults[0])) + 1;
+        punish_time = atoi((row[1] ? row[1] : defaults[1]));
     }
     if(!punishment && (warn & SPAMSETTINGS_SPAMSCAN) && settings->exceptlevel[SPAMSETTINGS_SPAMEXCINDEX] > uaccess) {
         sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_SPAM);