From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nc-smtp2.sdv.fr (nc-smtp2.sdv.fr [212.95.69.92]) by sourceware.org (Postfix) with ESMTPS id 3D0A4385840B for ; Mon, 11 Mar 2024 21:22:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D0A4385840B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=skarnet.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=skarnet.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3D0A4385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.95.69.92 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710192128; cv=none; b=OrGv4hDoIGSkH1fufrYWa8ioSrOnjgTzHmtO1qoW8+CdGrVOz5TkIos/ZKM/XBpm63kExMvAUXgaI+6PkVQ9smj4gTcqWGxzCLFAdcDG6NYrTMzSiVShkIwruXlBe2kH7U4CksVJHiLB3wkrMrckzOT3U42H0Lq5b8yYFl8J81Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710192128; c=relaxed/simple; bh=/39tNX1xSAJ9wmE1/3rlSijMzdn0Gk/WXVBmfbnx7nI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=qmg48o4DpSU1uN3Nplms8slp+Epgs7baf51PvjJzxyvRIhaRqcZGyGRYVGglYsd9bmgnbtuXnUONArpqIUnY39uyiIZNxc31bJ1mswz6VwDUQZvpBtCOKZvR0jeoj4dwQGdmXnJ82GBy2OdJ6pyWJZ4dEGt4BzvSDHUIntiBprM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from skarnet.org (140.156.124.78.rev.sfr.net [78.124.156.140]) by nc-smtp2.sdv.fr (Postfix) with SMTP id 3FEE9E16DD for ; Mon, 11 Mar 2024 22:21:00 +0100 (CET) Received: (qmail 20885 invoked from network); 11 Mar 2024 22:21:27 +0100 Received: from elzian.internal.skarnet.org. (HELO ?192.168.0.2?) () by sinay.internal.skarnet.org. with SMTP; 11 Mar 2024 22:21:27 +0100 From: "Laurent Bercot" To: musl@lists.openwall.com, "Skyler Ferrante (RIT Student)" Subject: Re: [musl] Re: Tweaking the program name for functions Cc: "Andreas Schwab" , "Alejandro Colomar" , "Thorsten Glaser" , musl@lists.openwall.com, NRK , "Guillem Jover" , libc-alpha@sourceware.org, libbsd@lists.freedesktop.org, "Serge E. Hallyn" , "Iker Pedrosa" , "Christian Brauner" Date: Mon, 11 Mar 2024 21:21:00 +0000 Message-Id: In-Reply-To: <20240311194756.GY4163@brightrain.aerifal.cx> References: <20240310193956.GU4163@brightrain.aerifal.cx> <20240310234410.GW4163@brightrain.aerifal.cx> <20240311194756.GY4163@brightrain.aerifal.cx> Reply-To: "Laurent Bercot" User-Agent: eM_Client/9.2.2157.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >(Aside: making _FORTIFY_SOURCE>1 trap close(n) with n<3 would be an >interesting idea... :) Please don't. close(0); if (open("something", O_RDONLY)) fail(); (only when single-threaded, obviously) is a valid pattern, and uses one fewer descriptor than fd=3Dopen("something", O_RDONLY); dup2(fd, 0); Also, running with stdin or stdout closed (or even stderr but what kind of monster would do that) is fine for a process that is internal to a project, that isn't user-facing; it's on the project to know the fd states of its various components. Private APIs should not have the same constraints as public ones. (And yes, for user-facing programs, i.e. 99% of them, it is a good idea to always sanitize around 0, 1 and 2.) -- Laurent