Browse Source

msg_qa now drops suspicious incomign messages on the floor and
it aborts only of messages sent out are suspicious

Jiri Kuthan 23 năm trước cách đây
mục cha
commit
f354fb0efc
1 tập tin đã thay đổi với 15 bổ sung5 xóa
  1. 15 5
      udp_server.c

+ 15 - 5
udp_server.c

@@ -234,6 +234,13 @@ int udp_rcv_loop()
 			len--;
 		}
 #endif
+#ifdef DBG_MSG_QA
+		if (!dbg_msg_qa(buf, len)) {
+			LOG(L_WARN, "WARNING: an incoming message didn't pass test, drop it: %.*s\n",
+				len, buf );
+			continue;
+		}
+#endif
 		
 		/* receive_msg must free buf too!*/
 		receive_msg(buf, len, from);
@@ -259,7 +266,7 @@ error:
    in generated messages; this debugging option aborts if
    any such message is sighted
 */
-void dbg_msg_qa(char *buf, int len)
+int dbg_msg_qa(char *buf, int len)
 {
 #define _DBG_WS_LEN 3
 #define _DBG_WS "   "
@@ -273,7 +280,7 @@ void dbg_msg_qa(char *buf, int len)
 	/* is there a zero character inthere ? */	
 	if (memchr(buf, 0, len)) {
 		LOG(L_CRIT, "BUG: message being sent with 0 in it\n");
-		abort();
+		return 0;
 	}
 
 	my_len=len;
@@ -288,7 +295,7 @@ void dbg_msg_qa(char *buf, int len)
 							if (space_cnt==4) {
 								LOG(L_CRIT, "BUG(propably): DBG_MSG_QA: "
 									"too many spaces\n");
-								abort();
+								return 0;
 							}
 						} else space_cnt=0;
 						state=QA_SPACE; 
@@ -314,7 +321,7 @@ void dbg_msg_qa(char *buf, int len)
 
 
 qa_passed:
-	return;
+	return 1;
 }
 
 #endif
@@ -328,7 +335,10 @@ int udp_send(struct socket_info *source, char *buf, unsigned len,
 
 #ifdef DBG_MSG_QA
 	/* aborts on error, does nothing otherwise */
-	dbg_msg_qa( buf, len );
+	if (!dbg_msg_qa( buf, len )) {
+		LOG(L_ERR, "ERROR: udp_send: dbg_msg_qa failed\n");
+		abort();
+	}
 #endif