fixed crash in cmd_NeonServ.mod/cmd_neonserv_mode.c
[NeonServV5.git] / src / modules / NeonServ.mod / cmd_neonserv_mode.c
index 9aae43e9374209395f8d70e512c064148323652e..d153ffa53757f847287afd77f10a692a3411d336 100644 (file)
@@ -34,7 +34,7 @@ struct neonserv_cmd_mode_cache {
 CMD_BIND(neonserv_cmd_mode) {
     struct neonserv_cmd_mode_cache *cache = malloc(sizeof(*cache));
     if (!cache) {
-        perror("malloc() failed");
+        printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
         return;
     }
     cache->client = client;
@@ -64,7 +64,7 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
     modeBuf = initModeBuffer(client, chan);
     printf_mysql_query("SELECT `channel_canop`, `channel_canvoice`, `channel_canban`, `channel_enfmodes`, `channel_modes` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
     row = mysql_fetch_row(mysql_use());
-    if(row[0] == NULL || row[1] == NULL || row[2] == NULL || row[3] == NULL) {
+    if(row[0] == NULL || row[1] == NULL || row[2] == NULL || row[3] == NULL || row[4] == NULL) {
         printf_mysql_query("SELECT `channel_canop`, `channel_canvoice`, `channel_canban`, `channel_enfmodes`, `channel_modes` FROM `channels` WHERE `channel_name` = 'defaults'");
         defaults = mysql_fetch_row(mysql_use());
     }
@@ -92,6 +92,7 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
     arg = 0;
     while(arg < argc) {
         char *modeStr = argv[arg++];
+        char modeStrBuf[3];
         for(i = 0; i < strlen(modeStr); i++) {
             switch(modeStr[i]) {
                 case '+':
@@ -103,7 +104,8 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
                 case 'o':
                 case 'v':
                     if(arg == argc) {
-                        reply(textclient, user, "NS_MODE_INVALID", modeStr[i]);
+                        sprintf(modeStrBuf, "%c%c", (add ? '+' : '-'), modeStr[i]);
+                        reply(textclient, user, "NS_MODE_INVALID", modeStrBuf);
                         return;
                     }
                     carg = argv[arg++];
@@ -152,7 +154,8 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
                     break;
                 case 'b':
                     if(arg == argc) {
-                        reply(textclient, user, "NS_MODE_INVALID", modeStr[i]);
+                        sprintf(modeStrBuf, "%c%c", (add ? '+' : '-'), modeStr[i]);
+                        reply(textclient, user, "NS_MODE_INVALID", modeStrBuf);
                         return;
                     }
                     carg = argv[arg++];
@@ -206,7 +209,8 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
                 default:
                     modetype = getModeType(modelock, modeStr[i]);
                     if(modetype == 0) {
-                        reply(textclient, user, "NS_MODE_INVALID", modeStr[i]);
+                        sprintf(modeStrBuf, "%c%c", (add ? '+' : '-'), modeStr[i]);
+                        reply(textclient, user, "NS_MODE_INVALID", modeStrBuf);
                         return;
                     }
                     if(isModeAffected(modelock, modeStr[i]) && add == !isModeSet(modelock, modeStr[i]) && uaccess < db_enfmodes) {
@@ -220,7 +224,7 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
                     }
                     if(add && (modetype & CHANNEL_MODE_TYPE) != CHANNEL_MODE_TYPE_D) {
                         if(arg == argc) {
-                            reply(textclient, user, "NS_MODE_INVALID", modeStr[i]);
+                            reply(textclient, user, "NS_MODE_INVALID", modeStr);
                             return;
                         }
                         carg = argv[arg++];
@@ -250,7 +254,7 @@ 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]);
+                            reply(textclient, user, "NS_MODE_INVALID", modeStr);
                             return;
                         }
                         carg = (arg == argc ? NULL : argv[arg++]);
@@ -278,7 +282,7 @@ static void neonserv_cmd_mode_async1(struct ClientSocket *client, struct ClientS
                                 modeBufferSimpleMode(modeBuf, add, modeStr[i]);
                             }
                         } else {
-                            reply(textclient, user, "NS_MODE_INVALID", modeStr[i]);
+                            reply(textclient, user, "NS_MODE_INVALID", modeStr);
                             return;
                         }
                     }