From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by sourceware.org (Postfix) with ESMTPS id 931BE3858D32 for ; Thu, 13 Jul 2023 16:25:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 931BE3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36DDfHSW027428 for ; Thu, 13 Jul 2023 18:25:18 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=GOYxcuD+fMV3iUQXO3xqkDSfzT9cbc2dJEdpgboeaGM=; b=WtxIk/yqC8unN8p4i5rzM0Aa5mieZ8nVnMSVXs+3DuGYHAGJi77voAXsYcpC69DincsG Uxlo0nMMfalXANZVrKMUS4rhcSe9X4xZStgAqU3v3hXTzCJ7l0Jci9zt5QZAWBpFnhbs dmoHOibXJYJKqblLsN72i8s6rU7Qgx7Kane35C/5AU7yBl8M4nlc92EXRa/zrHxFZ/eb IiBE8V5D+Lh5wdcHHfHLIWuuyQaXLe5GWTJJnAoAOsD+1a7Ksjg7NCP7uf8acMJoNMyL Rbog04XM2xXfGK9qQmjdqlTT1lruOwUkoxU6krVgm99znwBak0KgifPfPm8+WP1V/hi7 pg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3rtjce121v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 13 Jul 2023 18:25:18 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9148F100056 for ; Thu, 13 Jul 2023 18:25:17 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 8AB8722FA39 for ; Thu, 13 Jul 2023 18:25:17 +0200 (CEST) Received: from [10.252.3.53] (10.252.3.53) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 13 Jul 2023 18:25:18 +0200 Message-ID: <9ad091f5-4ca9-6410-e990-0cd4f1ece86e@foss.st.com> Date: Thu, 13 Jul 2023 18:25:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] Fix getlogin() to check only stdin to get a valid tty Content-Language: en-US To: References: <1de3b3ee-7dd8-db16-6e17-365dbd9fde84@fibranet.cat> <74633613-8420-5ad6-2882-6ad14066f781@foss.st.com> From: Torbjorn SVENSSON In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.252.3.53] X-ClientProxiedBy: EQNCAS1NODE3.st.com (10.75.129.80) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-13_06,2023-07-13_01,2023-05-22_02 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: On 2023-07-13 10:06, Jordi Sanfeliu via Newlib wrote: > Hello Torbjörn, > > Thanks for you reply. > > It seems to me that this code returns 0 as soon as one of the 3 fds is > 0, regardless if the rest are valid tty names. > > I think that what you meant is this: > >         if ((tty = ttyname (0)) == 0) >             if ((tty = ttyname (1)) == 0) >                 if ((tty = ttyname (2)) == 0) >                     return 0; > > which IMO would be even a better patch. > > What do you think? Actually, you're right. Sorry for the confusion. I took a sneak peak at how glibc does this and there is this comment: /* Get name of tty connected to fd 0. Return NULL if not a tty or if fd 0 isn't open. Note that a lot of documentation says that getlogin() is based on the controlling terminal---what they really mean is "the terminal connected to standard input". The getlogin() implementation of DEC Unix, SunOS, Solaris, HP-UX all return NULL if fd 0 has been closed, so this is the compatible thing to do. Note that ttyname(open("/dev/tty")) on those systems returns /dev/tty, so that is not a possible solution for getlogin(). */ Based on this comment, I guess it would be sane to drop the check on stdout and stderr, but it would have the consequence that you are not able to pipe some data on stdin to the application that calls getlogin as it would fail in that scenario. I'm not a maintainer of newlib so I don't really have anything to say about what path you decide to go.