From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18511 invoked from network); 13 Oct 2021 07:19:06 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 13 Oct 2021 07:19:06 -0000 Received: (qmail 16191 invoked by uid 550); 13 Oct 2021 07:19:04 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21984 invoked from network); 13 Oct 2021 01:21:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=eteau4a26zmxk2ijau6sgb3me4huyrhc; d=openwall.com.au; t=1634088092; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type; bh=T3DyuhdOKR8SzGPXFm5rXYcXBxx+cec6tNMVKBmbzeM=; b=SHGJ1rSLmh+iup9XcrydhnkvxRwuVYVGoCJT6kliOZYBGMAWLHTHSCXhoo/s7SBx 359B1CRz4FtDCmO3YOSp03bf+A9awNflvJcIYG1eCK+aCSlsnRXLPhIbjmtdfG3qzKx d8ENIV2Fxt5NArPI/6jrZYqrP03IUiYE4MpoZRJU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1634088092; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Feedback-ID; bh=T3DyuhdOKR8SzGPXFm5rXYcXBxx+cec6tNMVKBmbzeM=; b=IPbhl0GDLoaPanDSpFJ1BHkKrg9+KcKLaC+gyN3v/pwfB73Q/3JpHVpD3PkezvFT mWsE4eLHq5LhlcN66Hj7hlaH7OadxVLPqn9mNStz+iFTs7QzG6pBZDerxMzYZ+lgVCA hGs4pK+MG7Aop6DAarc9qGoPkg+4YjnJKLT7CIyg= ARC-Seal:i=1; a=rsa-sha256; d=openwall.com.au; s=20180402; t=1634088091; cv=none; b=EuHJpw6GnWS4O00ARqstquxB8zw5LITvcqL6EO46bODbGIXBbSJI6awXCDXrXMObqVxopGs9zuuEZe68/20ietZVY7r+bITky0EMlTqKhq740yonqyHELAYiuX3rkBOQTwRqb8z/QGjGKYVN601eBEoOuaA2TEjFvmJRW4qRJRWrS2K+WH3hTOrGRqWpkJvVcurLLTzK99adC4cnaIKy3Ln8pgvvxrrPOmB2qcXaXd+eR+yTI5G8N5oye/VsBK0Mw1G3qd0wctMTtBiHF9J8iCco03PYSRWV3OjXN/MrwvkIFt+haoNnx3WLrQYyzS5DCfSkxaqffwuYMTmqCaGLBw== ARC-Message-Signature:i=1; a=rsa-sha256; d=openwall.com.au; s=20180402; t=1634088091; c=relaxed/simple; bh=T3DyuhdOKR8SzGPXFm5rXYcXBxx+cec6tNMVKBmbzeM=; h=From:To:Subject; b=fh+Z5EtrDYWsquiv/sF4ExQgLejhWpeX2MtdyBKcQrB0qdUTf89es+Ya2sYSQafJ+QvCHxZfSOBNsGBno0G9/6ltpuRXNuwbrN8mb3A0N+7wAphG7ku/D53xbW6PPFf4ynaoYwWHmdpE1PNb+5dfAK6eORUjPgwpyV5PUgjfWDnUIlGBkiq0/+KBXy+Xkf9VvhOW3qLKaIbPSIspky6OFcT42cvc4303uPBaKGAEP+UVVOWQo0kcFsr0k5Mc285IzF82v2KyJYTVQNlKd6r5s4y4EZ2Tg/X1qXJ0xDm4EOCIBq9JEDEQstBPToYQnmRJIeuIdZidQHI/u/+kjBfj7w== ARC-Authentication-Results:i=1; mail.openwall.com.au; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=openwall.com.au; s=20180402; t=1634088091; bh=T3DyuhdOKR8SzGPXFm5rXYcXBxx+cec6tNMVKBmbzeM=; h=From:To:Subject:From; b=fymD0lYsZSjU4O+TG4ejMGQb4uHMwfRSfEa3ypnSF/1762POGPyDahJM957xcIUAg vzQFSGyji80VenCVYh/WToxOFm9TCY1Vw8g/XMOLZgJHZg7GGTc40I5a3HcfMAztsw ykv6dG3gEr5GKqrmrKINlV8soiRvpBkaSB1Y9jMyserxhu5N/mduXkjtEs3/z1GLfF oXo2Eq5Fwz3ugopG0adZjx7QBnhjrowsXRpnCVRCeOCTFMQs+4bc/z4u0IumuawlBo MBTzC9Wv2N7SZ9XlD3n5IiPoYb7z2If3/+vh+0XPajNti5iF5gxo/+hcs7I+/inpiY tNQkc7aW4auqQ== Date: Wed, 13 Oct 2021 01:21:31 +0000 From: "(GalaxyMaster)" To: musl@lists.openwall.com Message-ID: <0100017c773d8050-290fe58a-7804-4399-83f8-0ce8d845f7d2-000000@email.amazonses.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Feedback-ID: 1.us-east-1.Br0WpcLm0XzNPYp+t39aA5qSwb/HYCx3zC5wkQY3G2s=:AmazonSES X-SES-Outgoing: 2021.10.13-54.240.8.73 Subject: [musl] errno on writing to read-only files Hello, I am observing the following on musl and I am not sure that this is the way it should be: === galaxy@archlinux:~/musl-tests $ cat fput-to-readonly.c #include #include int main() { FILE *f; int i = 0; f = fopen("fput-to-readonly.c", "r"); errno = 0; i = fputs("should not be written", f); printf("i = %d (should be negative [EOF = %d])\n", i, EOF); printf("errno = %d\n", errno); return 0; } galaxy@archlinux:~/musl-tests $ gcc -o fput-to-readonly fput-to-readonly.c galaxy@archlinux:~/musl-tests $ ./fput-to-readonly i = -1 (should be negative [EOF = -1]) errno = 0 galaxy@archlinux:~/musl-tests $ === Logically, I would expect the errno variable to be set to something since there was clearly an error and the data has not been written to the destination. Glibc returns EBADF (9) in this case: === [galaxy@archlinux musl-tests]$ ./fput-to-readonly i = -1 (should be negative [EOF = -1]) errno = 9 [galaxy@archlinux musl-tests]$ === Should not we do the same? It kind of makes sense since the descriptor we are asked to write to is read-only. I think it would be just one line added to src/stdio/__towrite.c, something like: === --- musl-b76f37fd5625d038141b52184956fb4b7838e9a5.orig/src/stdio/__towrite.c 2021-09-24 00:09:22.000000000 +0000 +++ musl-b76f37fd5625d038141b52184956fb4b7838e9a5/src/stdio/__towrite.c 2021-10-13 01:16:04.713069382 +0000 @@ -5,6 +5,7 @@ int __towrite(FILE *f) f->mode |= f->mode-1; if (f->flags & F_NOWR) { f->flags |= F_ERR; + errno = EBADF; return EOF; } /* Clear read buffer (easier than summoning nasal demons) */ === -- (GM)