NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/57390: misleading error message in mq_send(3) for empty message



>Number:         57390
>Category:       kern
>Synopsis:       misleading error message in mq_send(3) for empty message
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 04 03:35:00 +0000 2023
>Originator:     Jan Schaumann
>Release:        NetBSD 9.3
>Organization:
	
>Environment:
	
	
System: NetBSD panix.netmeister.org 9.3 NetBSD 9.3 (PANIX-VC) #1: Wed Aug 17 12:34:21 EDT 2022 root%juggler.panix.com@localhost:/misc/obj64/misc/devel/netbsd/9.3/src/sys/arch/amd64/compile/PANIX-VC amd64
Architecture: x86_64
Machine: amd64
>Description:

When submitting a message of zero length using mq_send(3), errno is set to EMSGSIZE
in (I think) src/sys/kern/sys_mqueue.c #830:

/* Check the message size limit */
if (msg_len <= 0 || msg_len > mqattr->mq_msgsize) {
        error = EMSGSIZE;
        goto error;
}

strerror(EMSGSIZE) yields "Message too long", but in this case the error is
actually that the message is _too short_.

>How-To-Repeat:

$ cat >m.c <<EOF
#include <sys/stat.h>

#include <err.h>
#include <errno.h>
#include <mqueue.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define MQ_PATH             "/mq"
#define MQ_FLAGS            O_WRONLY | O_CREAT | O_EXCL | O_NONBLOCK
#define MQ_PERMS            S_IRUSR | S_IWUSR
#define MQ_MAXMSG           10
#define MQ_MSGSIZE          10
#define MQ_DEFAULT_PRIORITY 0

int
main(int argc, char **argv) {
	mqd_t mq;
	struct mq_attr attr;

	attr.mq_flags = 0;
	attr.mq_maxmsg = MQ_MAXMSG;
	attr.mq_msgsize = MQ_MSGSIZE;
	attr.mq_curmsgs = 0;

	(void)mq_unlink(MQ_PATH);

	if ((mq = mq_open(MQ_PATH, MQ_FLAGS, MQ_PERMS, &attr)) == (mqd_t)-1) {
		err(EXIT_FAILURE, "mq_open");
		/* NOTREACHED */
	}

	for (int i = 1; i < argc; i++) {
		if (mq_send(mq, argv[i], strlen(argv[i]), MQ_DEFAULT_PRIORITY) == -1) {
			(void)fprintf(stderr, "%s: Unable to send message %d: %s\n",
					getprogname(), i, strerror(errno));
		}
	}

	if (mq_close(mq) == -1) {
		err(EXIT_FAILURE, "mq_close");
		/* NOTREACHED */
	}

	(void)mq_unlink(MQ_PATH);

	return EXIT_SUCCESS;
}
EOF
$ cc m.c -lrt
$ ./a.out "" ok 012345678910
a.out: Unable to send message 1: Message too long
a.out: Unable to send message 3: Message too long
$

>Fix:

I don't know if this can be fixed, since EMSGSIZE sounds entirely reasonable,
and it's just the human readable representation that's misleading here, but
reporting this here just in case somebody has a clever idea.

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index