Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp3270777rwb; Sun, 30 Jul 2023 04:23:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHt8ZLhjj6zbQUat5q8Z99yshye/GjnaJrghE6JVJuWpYMEdwLegHapUUVVw3wmtl+FDTxJ X-Received: by 2002:a05:6a20:3d8e:b0:133:1d62:dcbd with SMTP id s14-20020a056a203d8e00b001331d62dcbdmr7684381pzi.28.1690716208807; Sun, 30 Jul 2023 04:23:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690716208; cv=none; d=google.com; s=arc-20160816; b=HUsttvm5wcCHT7XFQ8ySH4yZBbP0eZGZS9cbH+2EwE+/U/BxFCsZMewNOREjegUVJP yw6b0yQM8siKUaX+075mGa9tv7U0P9KUuPmBm3z7x9dqWjR8fB8qdht0jExsemNnS0e+ Vm+CRlT2frRGxRX2dXqsWE12iWQvvrEdFXZkulfn8HYFoLnumO2PBr/odrAWewUSK0DA cOsTS/ezWIBsivVh6gfsUqSjywOIcTr3fv8NcaBK8ZiK6FGtbtuwQU1XOyPw3ZK37Dcz c+bO15UlTF8eRIXXnyBvpPtE2HG/RwYAVs3Zg5lydkFiwXwLSOS6hVnvGy1s090wdhzg 4mHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8JfFoJ+hMWOclygvDdN1V+NE1+v1N6FWjxYY+1743uc=; fh=reTQtKv4WHzRhS6OElR4c5ve1y+8sIrINaYNuYT+ztw=; b=ny14qrAyRG0AUQe09B4Rj71L9qQl53u3Va3w1tHeVb5xTazQ6LKGjxc9uNLGkexgMJ UxnZRpdAMOrm2N+4tlpJu3gZWXgsFEIpoYpQ7IHIIRyCANgTO9Ofv4jUOAaFDHhSEQbO S4FVfNEuCBN/61/DeO85slw2WdoSuG6w71/eCXVadtmocBFSIM2tXFQmhz8R5pBS1DF6 Xzrs8TgkLoVxeXgx0Z9TH8Klr692uZUvNIhkvhHjepPTDNUt6PMZw9N8LhaSNQVgcoKS Yw3xVg93N6BXW9FQfbT7W+7SUlntEFKxdvedtp+PC2r+0GEH+wLCrcUUOgNiTQt5CVT5 Vz9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q24-20020a637518000000b005644f022c68si5620pgc.159.2023.07.30.04.23.16; Sun, 30 Jul 2023 04:23:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbjG3LIq (ORCPT + 99 others); Sun, 30 Jul 2023 07:08:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjG3LIp (ORCPT ); Sun, 30 Jul 2023 07:08:45 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 66DC91BD1; Sun, 30 Jul 2023 04:08:42 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 36UB8XUv012520; Sun, 30 Jul 2023 13:08:33 +0200 Date: Sun, 30 Jul 2023 13:08:33 +0200 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: Yuan Tan , falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 2/2] selftests/nolibc: add testcase for pipe. Message-ID: <20230730110833.GA12462@1wt.eu> References: <160ddef0313e11085ee906144d6d9678b8156171.1690307717.git.tanyuan@tinylab.org> <27bd9bc1-e7a5-4a81-91c9-2642feabb7ce@t-8ch.de> <20230730033343.GB7339@1wt.eu> <20230730071227.GB8033@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 30, 2023 at 10:07:24AM +0200, Thomas Wei?schuh wrote: > > In fact you make a good point regarding the fact that the test doesn't > > use read()'s return value. This problem totally goes away if the return > > value is used, e.g.: > > > > len = read(pipefd[0], buf, sizeof(buf)); > > close(pipefd[0]); > > waitpid(pid, NULL, 0); > > return len < 0 || len > sizeof(buf) || len > strlen(msg) || memcmp(buf, msg, len) != 0; > > Wouldn't this happily accept len == 0? > > Why not just: > > if (len != strlen(msg)) > return 1; > return !!memcmp(buf, msg, len); Indeed, works for me. > Also so far we have assumed that one call one call to read() is enough. > But looking at pipe(7) this is not guaranteed by the spec. > If we want to be really sure, a loop around read() seems to be necessary. In practice it will be OK as the message is small and sent in one syscall, so let's not care too much about this for now. Willy