From nobody Mon May 04 15:45:22 2026 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g8Qvk4tDNz6bh55 for ; Mon, 04 May 2026 15:45:22 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g8Qvk2lH7z3hmN for ; Mon, 04 May 2026 15:45:22 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777909522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=opd6+CW5CGfNrxvD3+gQG4IajfciMHxq9y7/jz61e6Y=; b=l98nEHcD+P43+Q2++ucU+n/pRl2wOY/DgP/uCznBNEXyIK+M0CtU2s63D7ZLzUfgHkaIlI ssnqN3ElSmhJ77HQxuv2xEMEfx/K2r4X8fCMMrQMF3jRUQpdpMAppWrxgm0LYqO+OU3rqn af56JVk84ueo7IHsb5LpAoK3YmRu7j8axGeJRuytKR4zqNattIiTg6uZTn5Elbs/52iXZa cupVjBs1xIq891SySnu7wApJ0Kbm0mgKIsY61TBStSKQexts3Tn6rN2tK36Hge3sY652f8 tTJMw4QFb8wziFPR6qPgaHIIQXgOdgM0C1vxo3aoKQ8kQEq0Q9rZ35FGcu/q4Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777909522; a=rsa-sha256; cv=none; b=hI7uLYk5vcnYqJ1TYtXcegU2Vn5zwJRGEhFPEhl6DWsq7xj9KgCxvRAhh4NjEHQXXdJplJ wSuK8AF7MlMMTv8nal0BWcabjNkqL73etXieTtaL61A5ucGQYBhaoAcNfYq5TO+s5Na6X8 KKGas3jMBVWdOGiAUjVIaSa7jBvj1v5/QoIR/xvv9wAi94FhV/Y558B3BdG+yc0kW9l4nJ 1sgMZNwGCPwE7y8ihCWxAZLSKNSOoaWLAEhOUZULC4irXe2nGE5Du4Tmx37d1yxm7bwsu7 MMzEX9eRpsZlIr68K3ueS4aeVz0M5ht5fBfWdx64UC+QAFs0dGvOwqeaigmHYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777909522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=opd6+CW5CGfNrxvD3+gQG4IajfciMHxq9y7/jz61e6Y=; b=Dj8Rpp3lYl7tF3q2nzlWVO8PGxvY+20Z0xybxnel309Z3KSfAEUVBcryRVzi0pVmQrJEGX p6p5TZ8Cy6Kjewy1nb/9UPj34qFrSTShcx3P9w4aN6ikqCJusspyrqE9vSYLSbMlkF4puc Y5aPt+WQe3aacwMvApwiMD7Rev1VldSSkAqmH2JB1L/XyLKbUj2cURB3Nut0LB8MmAXySq jzBnBgBeqTW/HlH9WLSEB5aIAul63dmloU5ymI1ORlquq7I1Mgw7Rnk12GSZ3qWwyS27GW K0/SceyKYtKQMzn2rBIvcYpd+pzneKYkmzEj7ksnibGfNLICEaA4krhbKdGXzA== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4g8Qvk1lYCzB4N for ; Mon, 04 May 2026 15:45:22 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 644FjMnk008515 for ; Mon, 4 May 2026 15:45:22 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 644FjM73008514 for bugs@FreeBSD.org; Mon, 4 May 2026 15:45:22 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 295009] UDP receive with zero-size buffer immediately returns, no wait, no EAGAIN Date: Mon, 04 May 2026 15:45:22 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 15.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: thierry@lelegard.fr X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D295009 Bug ID: 295009 Summary: UDP receive with zero-size buffer immediately returns, no wait, no EAGAIN Product: Base System Version: 15.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Many People Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: thierry@lelegard.fr On FreeBSD 15.0-RELEASE-p8, receiving a UDP datagram using recv(), recvfrom= (), or recvmsg() with a zero-size data buffer immediately returns with value ze= ro, even when no datagram is sent, even when the socket is in non-blocking mode. According to the POSIX spec and the FreeBSD man pages, when zero is specifi= ed as reception buffer size, the correct behaviour should be: - In blocking mode: wait for a datagram, return zero, optionally report the truncation of the message in flags. - In non-blocking mode, when no message is immediately available, return -1 and set errno to EAGAIN. Other operating systems: - macOS 26.4.1 behaves as FreeBSD. The bug is probably in their common root= s. - Linux 7.0: expected POSIX behaviour. The following code reproduces the problem. It opens a UDP socket, binds it = to 127.0.0.1:1234, and receives a message (typically a text string to display). There are two parameters: receive buffer size and optional non-blocking mod= e. Syntax: udpzero [bufsize [-n]] bufsize : receive buffer size, default: 256 -n : non-blocking Sample command to send a 4-byte message using bash: echo -n "abcd" >/dev/udp/127.0.0.1/1234 On FreeBSD 15.0-RELEASE-p8 and macOS 26.4.1: $ ./udpzero receive buffer size: 256, blocking mode [... wait for a message ...] received size: 4, data: "abcd" $ $ ./udpzero 10 -n receive buffer size: 10, non-blocking mode recv: Resource temporarily unavailable $ $ ./udpzero 0 receive buffer size: 0, blocking mode received size: 0, data: "" $ $ ./udpzero 0 -n receive buffer size: 0, non-blocking mode received size: 0, data: "" On Linux 7.0 (Ubuntu 26.04): $ ./udpzero receive buffer size: 256, blocking mode [... wait for a message ...] received size: 4, data: "abcd" $ $ ./udpzero 10 -n receive buffer size: 10, non-blocking mode recv: Resource temporarily unavailable $ $ ./udpzero 0 receive buffer size: 0, blocking mode [... wait for a message ...] received size: 0, data: "" $ $ ./udpzero 0 -n receive buffer size: 0, non-blocking mode recv: Resource temporarily unavailable ----------------------------------------------------- #include #include #include #include #include #include #include #include void check(int cond, const char* message) { if (!cond) { perror(message); exit(EXIT_FAILURE); } } int main(int argc, char* argv[]) { const int bufsize =3D argc < 2 ? 256 : atoi(argv[1]); const int nonblock =3D argc >=3D 3 && strcmp(argv[2], "-n") =3D=3D 0; printf("receive buffer size: %d, %sblocking mode\n", bufsize, nonblock ? "non-" : ""); char* data =3D malloc(bufsize); check(data !=3D NULL, "malloc"); int sock =3D socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); check(sock >=3D 0, "socket"); if (nonblock) { int flags =3D fcntl(sock, F_GETFL, 0); check(flags !=3D -1, "fcntl"); flags =3D fcntl(sock, F_SETFL, flags | O_NONBLOCK); check(flags !=3D -1, "fcntl"); } struct sockaddr_in addr; addr.sin_family =3D AF_INET; addr.sin_addr.s_addr =3D htonl(0x7F000001); // 127.0.0.1 addr.sin_port =3D htons(1234); int status =3D bind(sock, (struct sockaddr*)&addr, sizeof(addr)); check(status =3D=3D 0, "bind"); socklen_t len =3D sizeof(addr); ssize_t insize =3D recvfrom(sock, data, bufsize, 0, (struct sockaddr*)&= addr, &len); check(insize >=3D 0, "recv"); printf("received size: %ld, data: \"%.*s\"\n", insize, (int)insize, dat= a); close(sock); return EXIT_SUCCESS; } --=20 You are receiving this mail because: You are the assignee for the bug.=