From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 913D4C04A94 for ; Sun, 30 Jul 2023 11:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229973AbjG3LIr (ORCPT ); Sun, 30 Jul 2023 07:08:47 -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) 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