Commit Diff


commit - 182b48dc821a0a4cf7bbcfcdf5f9d376136fd7e6
commit + fbeaf87b54479383a77dc1fc41318bb788267154
blob - 46b1580bded14c39a8f459de78093768df1ec8b5
blob + 40c9054fac901264fe7318860cfcf86e61265e3d
--- kamid/client.c
+++ kamid/client.c
@@ -41,6 +41,11 @@
 #include "log.h"
 #include "sandbox.h"
 #include "utils.h"
+
+/*
+ * Max message size aviable via a single imsg.
+ */
+#define IMSG_MAXSIZE (MAX_IMSGSIZE - IMSG_HEADER_SIZE)
 
 /*
  * The minimum value allowed for the msize.
@@ -1974,6 +1979,13 @@ handle_message(struct imsg *imsg, size_t len, int cont
 		writetag = hdr.tag;
 		twrite(&hdr, data, len, &writefid, &writepos, &writeleft,
 		    &writeskip);
+		return;
+	}
+
+	if (len > IMSG_MAXSIZE) {
+		log_warnx("can't handle message: too long for its type");
+		client_send_listener(IMSG_CLOSE, NULL, 0);
+		client_shutdown();
 		return;
 	}