Quellcode durchsuchen

Detect if FiSH decryption failed or not (#25)

Bryan Drewery vor 14 Jahren
Ursprung
Commit
e21e1336e4
1 geänderte Dateien mit 13 neuen und 2 gelöschten Zeilen
  1. 13 2
      src/mod/server.mod/servmsg.c

+ 13 - 2
src/mod/server.mod/servmsg.c

@@ -187,8 +187,19 @@ static int check_bind_raw(char *from, char *code, char *msg)
 
         if (sharedKey.length()) {
           // Decrypt the message before passing along to the binds
-          bd::String cleartext(bd::String(msg, colon - msg) + egg_bf_decrypt(ciphertext, sharedKey));
-          mymsg = p2 = strdup(cleartext.c_str());
+          const bd::String decrypted(egg_bf_decrypt(ciphertext, sharedKey));
+          // Does the decrypted text make sense? If not, the key is probably invalid, reset it.
+          bool isValidCipherText = true;
+          for (size_t i = 0; i < decrypted.length(); ++i) {
+            if (!isprint(decrypted[i])) {
+              isValidCipherText = false;
+              break;
+            }
+          }
+          if (isValidCipherText) {
+            bd::String cleartext(bd::String(msg, colon - msg) + decrypted);
+            mymsg = p2 = strdup(cleartext.c_str());
+          }
         }
       }
     }