void send_fd(int sockfd, int fd)
{
	int bytes_written;
	struct msghdr msg = { };
	struct cmsghdr *cmsg;
	struct iovec iov[1] = { };
	char null_byte = '\0';

	iov[0].iov_base = &null_byte;
	iov[0].iov_len = 1;

	msg.msg_iov = iov;
	msg.msg_iovlen = 1;

	/* We send only one fd as specified by cmsg->cmsg_len below, even
	 * though msg.msg_controllen might have more space due to alignment. */
	msg.msg_controllen = CMSG_SPACE(sizeof(int));
	msg.msg_control = malloc(msg.msg_controllen);
	if (msg.msg_control == NULL) {
		bail("Can't allocate memory to send fd.");
	}

	memset(msg.msg_control, 0, msg.msg_controllen);

	cmsg = CMSG_FIRSTHDR(&msg);
	cmsg->cmsg_level = SOL_SOCKET;
	cmsg->cmsg_type = SCM_RIGHTS;
	cmsg->cmsg_len = CMSG_LEN(sizeof(int));
	memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));

	bytes_written = sendmsg(sockfd, &msg, 0);

	free(msg.msg_control);

	if (bytes_written != 1)
		bail("failed to send fd %d via unix socket %d", fd, sockfd);
}
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.