From nobody Wed Oct 09 12:06:42 2024 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 4XNs7R2pyFz5YS9k for ; Wed, 09 Oct 2024 12:06:43 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XNs7Q6NWqz4V3c for ; Wed, 9 Oct 2024 12:06:42 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728475602; 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=CasjZDbNRQD3j/P8hu5GgiD6JczAiAoKLwWl6Hbg2ZA=; b=nfSMX6yLOrvbAoOOMJbCgGyFS4BkQq8auMK96PmxddjoXxlJ76w5v86/VtJ/hH9gurv7h/ HduzDRSzI+7OcaON04VC0+FLOm2take7ro+bZ2uI/KzUai9hNDkEHNdvxKu9GeBx63EGcc MwNBO5OCLGFTuIT8OHDmFMcTcxPG5Oi7BLgumW/kEdBTlsapMW5AZrFYz7KGXUdetxMNFy szjNMqDovlHq0q2bCeObk5nlskYTIS47AP5uhEdP/4sKqVC9jUbZxy/rxAVHyi7zXSqa5j ZwFqIkpEgJmN5vwo2oXViGtxgeXEfrMp6WDFVGfUTtFFLMV2g0qSqxzHuE5neQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728475602; a=rsa-sha256; cv=none; b=B97jFoun4mv/P2ANvtc+1aWO8XgeSzSemvpb1z5p2G5P/Vdm/7WzYA+RJLCIkGqXpBRMgc c2TNje/HuNUAvXyQVd3cZLJ1ZIaYt/pXPMog4cBjvTrBeho/YlT6wDKigOxCr3flJrPq+I OLHmbMUUp7emUq6ZF5hy+RSzMu4yvm+u7gkkELs2hxhERB6cEaH57lXj8KteGzHoTcoXU/ ccsb08SHrXze/BCtz92+JSPxrZpCjHmbKY72q68F/iqwc8gJcsTSTTyw1OHbJuZaXSyrhw 1fkglMiw3r22j8ccnXySc4sydvXcSvr8cWa3HksBpv3wTZqjs1BMH/+6QtWjCw== 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 4XNs7Q5sj3z1Clc for ; Wed, 9 Oct 2024 12:06:42 +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 499C6g2m012414 for ; Wed, 9 Oct 2024 12:06:42 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 499C6ggD012413 for bugs@FreeBSD.org; Wed, 9 Oct 2024 12:06:42 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 281953] The fmemopen() function in libc/stdio opens a stream for writing even if the stream is specified as read-only Date: Wed, 09 Oct 2024 12:06:42 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 14.1-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: erkki.moorits@mail.ee 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 attachments.mimetype attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D281953 Bug ID: 281953 Summary: The fmemopen() function in libc/stdio opens a stream for writing even if the stream is specified as read-only Product: Base System Version: 14.1-RELEASE Hardware: amd64 OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: erkki.moorits@mail.ee Attachment #254107 text/plain mime type: Created attachment 254107 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D254107&action= =3Dedit Test code for fmemopen(.., .., "r") When memory buffer is opened in read-only mode with the fmemopen(.., .., "r= ") function, then the stream opened in read-write mode. Attached test code with this issue report. Expected result is (this compiled and run on Ubuntu Linux): buffer before: 'Hello123' buffer after: 'Hello123' fprintf result: -1 Test code, compiled and run on FreeBSD 14.1, give following output: buffer before: 'Hello123' buffer after: 'test:1' fprintf result: 6=20 Possible cause of this issue are on following lines: https://cgit.freebsd.org/src/tree/lib/libc/stdio/fmemopen.c#n139 f =3D funopen(ck, flags & O_WRONLY ? NULL : fmemopen_read,=20 flags & O_RDONLY ? NULL : fmemopen_write, fmemopen_seek, fmemopen_close); where 'flags & O_RDONLY' give always result 0;=20 But it should be like this (needs testing): f =3D funopen(ck, (flags & O_ACCMODE) =3D=3D O_WRONLY ? NULL : fmemopen_read,=20 (flags & O_ACCMODE) =3D=3D O_RDONLY ? NULL : fmemopen_write, fmemopen_seek, fmemopen_close); Or this (needs testing): f =3D funopen(ck, rc & __SWR ? NULL : fmemopen_read,=20 rc & __SRD ? NULL : fmemopen_write, fmemopen_seek, fmemopen_close); --=20 You are receiving this mail because: You are the assignee for the bug.=