From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) by sourceware.org (Postfix) with ESMTPS id 0608E385840F for ; Tue, 5 Mar 2024 21:51:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0608E385840F Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=m.gmane-mx.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0608E385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=116.202.254.214 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709675469; cv=none; b=rok0jxpSK41ToiksP6yv/1KjyvAXAKA6izLDc1xD8xsur3HxEQcu6bLTumPBQofvhTcglXXBsUUT+KGIt9IUz/OOjLLQGiMydBJyebMnvVf0dU2HMUJe+89VRRW6IWXpG/j8JR1AcjOqzehfs/8lyqj+wO6uSMNzOuNZOgpvVGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709675469; c=relaxed/simple; bh=scJH6wOKBMl3II0VbM4d8KxFXZVH8BDmrxQn0/subjU=; h=To:From:Subject:Date:Message-ID:Mime-Version; b=GzRlZgfVSLYbfyCgkXypmmcfIgexDFrnUdEE8932XblTH7cZ/CDX4+afEez6V5FCS55QyQp8OVIuBR7gGG2yDdLVIn/KzND9WyACOUQvzQ5Jq93aqRHa++wUVkygjidfIp6kqtJZzjvNaJYZw1+TvVyv1XRq5Qy39Qes6UaBZoI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1rhcgk-0001ou-L9 for gcc-patches@gcc.gnu.org; Tue, 05 Mar 2024 22:51:06 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: gcc-patches@gcc.gnu.org From: Harald Anlauf Subject: Re: [patch, libgfortran] Part 2: PR105456 Child I/O does not propage iostat Date: Tue, 5 Mar 2024 22:51:01 +0100 Message-ID: References: <943c3685-c4d4-4f22-8b65-6336f8770043@gmail.com> <20240229104705.62e46010@nbbrfq.loc> <033ebcdd-6e25-4af7-9012-3338978751d8@gmail.com> <05A1AEE6-6A68-4D4F-8BEA-6E87969E19E7@gmail.com> <65b13e02-bc1d-4cad-98cc-cf5d6090b742@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla Thunderbird Content-Language: en-US In-Reply-To: Cc: fortran@gcc.gnu.org X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,BODY_8BITS,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20240305215101.RTeg3g_snGgELCb5qFeANLdMcHlqC1N32hyVhtpd-H0@z> Hi Jerry, on further thought, do we sanitize 'child_iomsg'? We pass it to snprintf as format. Wouldn't a strncpy be sufficient? Harald On 3/5/24 22:37, Harald Anlauf wrote: > Hi Jerry, > > I think there is the risk of buffer overrun in the following places: > > +             char message[IOMSG_LEN]; > +             child_iomsg_len = string_len_trim (IOMSG_LEN, child_iomsg) > + 1; >               free_line (dtp); >               snprintf (message, child_iomsg_len, child_iomsg); >               generate_error (&dtp->common, dtp->u.p.child_saved_iostat, > > plus several more.  Wouldn't it be better to increase the size of > message by one? > > Thanks, > Harald > > > On 3/5/24 04:15, Jerry D wrote: >> On 3/1/24 11:24 AM, rep.dot.nop@gmail.com wrote: >>> Hi Jerry and Steve, >>> >>> On 29 February 2024 19:28:19 CET, Jerry D wrote: >>>> On 2/29/24 10:13 AM, Steve Kargl wrote: >>>>> On Thu, Feb 29, 2024 at 09:36:43AM -0800, Jerry D wrote: >>>>>> On 2/29/24 1:47 AM, Bernhard Reutner-Fischer wrote: >>>>>> >>>>>>> And, just for my own education, the length limitation of iomsg to >>>>>>> 255 >>>>>>> chars is not backed by the standard AFAICS, right? It's just our >>>>>>> STRERR_MAXSZ? >>>>>> >>>>>> Yes, its what we have had for a long lone time. Once you throw an >>>>>> error >>>>>> things get very processor dependent. I found MSGLEN set to 100 and >>>>>> IOMSG_len >>>>>> to 256. Nothing magic about it. >>>>>> >>>>> >>>>> There is no restriction on the length for the iomsg-variable >>>>> that receives the generated error message.  In fact, if the >>>>> iomsg-variable has a deferred-length type parameter, then >>>>> (re)-allocation to the exact length is expected. >>>>> >>>>>     F2023 >>>>> >>>>>     12.11.6 IOMSG= specifier >>>>> >>>>>     If an error, end-of-file, or end-of-record condition occurs during >>>>>     execution of an input/output statement, iomsg-variable is assigned >>>>>     an explanatory message, as if by intrinsic assignment. If no such >>>>>     condition occurs, the definition status and value of >>>>> iomsg-variable >>>>>     are unchanged. >>>>>    character(len=23) emsg >>>>> read(fd,*,iomsg=emsg) >>>>> >>>>> Here, the generated iomsg is either truncated to a length of 23 >>>>> or padded with blanks to a length of 23. >>>>> >>>>> character(len=:), allocatable :: emsg >>>>> read(fd,*,iomsg=emsg) >>>>> >>>>> Here, emsg should have the length of whatever error message was >>>>> generated. >>>>>    HTH >>>>> >>>> >>>> Well, currently, if someone uses a larger string than 256 we are >>>> going to chop it off. >>>> >>>> Do we want to process this differently now? >>> >>> Yes. There is some odd hunk about discrepancy of passed len and >>> actual len afterwards in 22-007-r1, IIRC. Didn't look closely though. >>> >> --- snip --- >> >> Attached is the revised patch using the already available >> string_len_trim function. >> >> This hunk is only executed if a user has not passed an iostat or iomsg >> variable in the parent I/O statement and an error is triggered which >> terminates execution of the program. In this case, the iomsg string is >> provided in the usual error message in a "processor defined" way. >> >> (F2023): >> >> 12.6.4.8.3 Executing defined input/output data transfers >> --- >> 11 If the iostat argument of the defined input/output procedure has a >> nonzero value when that procedure returns, and the processor therefore >> terminates execution of the program as described in 12.11, the >> processor shall make the value of the iomsg argument available in a >> processor-dependent manner. >> --- >> >> OK for trunk? >> >> Regards, >> >> Jerry >> >> > > >