xref: /openbsd-src/regress/sys/netinet/recvmsg/recvmsg.c (revision dced67ef7960ef7d804387299ffeb57b7deb912e)
1*dced67efSanton /*	$OpenBSD: recvmsg.c,v 1.2 2018/07/08 02:18:51 anton Exp $	*/
27f3a4606Santon /*
37f3a4606Santon  * Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
47f3a4606Santon  *
57f3a4606Santon  * Permission to use, copy, modify, and distribute this software for any
67f3a4606Santon  * purpose with or without fee is hereby granted, provided that the above
77f3a4606Santon  * copyright notice and this permission notice appear in all copies.
87f3a4606Santon  *
97f3a4606Santon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
107f3a4606Santon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
117f3a4606Santon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
127f3a4606Santon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
137f3a4606Santon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
147f3a4606Santon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
157f3a4606Santon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
167f3a4606Santon  */
177f3a4606Santon 
187f3a4606Santon /*
197f3a4606Santon  * Regression test for double free of mbuf caused by rip{6,}_usrreq().
207f3a4606Santon  */
217f3a4606Santon 
227f3a4606Santon #include <sys/socket.h>
237f3a4606Santon 
247f3a4606Santon #include <assert.h>
257f3a4606Santon #include <err.h>
267f3a4606Santon #include <errno.h>
277f3a4606Santon #include <stdio.h>
287f3a4606Santon #include <stdlib.h>
297f3a4606Santon #include <string.h>
307f3a4606Santon #include <unistd.h>
317f3a4606Santon 
327f3a4606Santon static __dead void usage(void);
337f3a4606Santon 
347f3a4606Santon int
main(int argc,char * argv[])357f3a4606Santon main(int argc, char *argv[])
367f3a4606Santon {
377f3a4606Santon 	struct msghdr msg;
387f3a4606Santon 	ssize_t n;
397f3a4606Santon 	int c, s;
407f3a4606Santon 	int domain = -1;
417f3a4606Santon 	int type = -1;
427f3a4606Santon 
437f3a4606Santon 	while ((c = getopt(argc, argv, "46dr")) != -1)
447f3a4606Santon 		switch (c) {
457f3a4606Santon 		case '4':
467f3a4606Santon 			domain = AF_INET;
477f3a4606Santon 			break;
487f3a4606Santon 		case '6':
497f3a4606Santon 			domain = AF_INET6;
507f3a4606Santon 			break;
517f3a4606Santon 		case 'd':
527f3a4606Santon 			type = SOCK_DGRAM;
537f3a4606Santon 			break;
547f3a4606Santon 		case 'r':
557f3a4606Santon 			type = SOCK_RAW;
567f3a4606Santon 			break;
577f3a4606Santon 		default:
587f3a4606Santon 			usage();
597f3a4606Santon 		}
607f3a4606Santon 	argc -= optind;
617f3a4606Santon 	argv += optind;
627f3a4606Santon 	if (argc > 0 || domain == -1 || type == -1)
637f3a4606Santon 		usage();
647f3a4606Santon 
657f3a4606Santon 	s = socket(domain, type, 0);
667f3a4606Santon 	if (s == -1)
677f3a4606Santon 		err(1, "socket");
687f3a4606Santon 	memset(&msg, 0, sizeof(msg));
697f3a4606Santon 	n = recvmsg(s, &msg, MSG_OOB);
707f3a4606Santon 	assert(n == -1);
717f3a4606Santon 	assert(errno == EOPNOTSUPP);
727f3a4606Santon 	close(s);
737f3a4606Santon 
747f3a4606Santon 	return 0;
757f3a4606Santon }
767f3a4606Santon 
777f3a4606Santon static __dead void
usage(void)787f3a4606Santon usage(void)
797f3a4606Santon {
807f3a4606Santon 	fprintf(stderr, "usage: recvmsg [-46dr]\n");
817f3a4606Santon 	exit(1);
827f3a4606Santon }
83