--- sys/kern/uipc_syscalls.c.orig
+++ sys/kern/uipc_syscalls.c
@@ -1699,6 +1699,9 @@
 	struct mbuf *m;
 	int error;
 
+	if (buflen < 0)
+		return (EINVAL);
+
 	if (buflen > MLEN) {
 #ifdef COMPAT_OLDSOCK
 		if (type == MT_SONAME && buflen <= 112)
