Browse Source

vccd: check magic

intirain 4 years ago
parent
commit
0498858047
3 changed files with 14 additions and 2 deletions
  1. 1 1
      Makefile
  2. 1 1
      include/vcc/version.h
  3. 12 0
      vcc.c

+ 1 - 1
Makefile

@@ -1,5 +1,5 @@
 VCCD_MAJOR 		= 0
-VCCD_MINOR 		= 2
+VCCD_MINOR 		= 3
 VCCD_PATCH 		= 0
 VCCD_COMPILE_TIME 	= $(shell date)
 VCCD_COMPILE_BY 	= $(shell whoami)

+ 1 - 1
include/vcc/version.h

@@ -1 +1 @@
-#define VCCD_VERSION "vccd 0.2.0 Sun Mar  6 12:20:25 CST 2022 root"
+#define VCCD_VERSION "vccd 0.2.0 Sun Mar  6 13:00:08 CST 2022 root"

+ 12 - 0
vcc.c

@@ -202,6 +202,18 @@ int vcc_message_broadcast(char *msg, char *usrname) {
 int vcc_new_msg(int fd, struct vcc_request *req) {
 	char *msg = req->msg;
 
+	if (unlikely(ntohl(req->magic) != VCC_MAGIC)) {
+		vcc_log("--- bad magic number from %d\n", fd);
+
+		return 0;
+	}
+
+	if (unlikely(htonl(req->reqtype) != REQ_MSG_SEND)) {
+		vcc_log("--- request's type is not REQ_MSG_SEND from %d\n", fd);
+
+		return 0;
+	}
+
 	if (((unsigned char *) msg)[0] == 0xffu || !*msg) 
 		return 0;