From patchwork Mon Jun 21 06:07:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1494904 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::33a; helo=mail-ot1-x33a.google.com; envelope-from=swupdate+bncbcwivbv7sugrbp6zycdamgqethv4xoi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=blpTotyW; dkim-atps=neutral Received: from mail-ot1-x33a.google.com (mail-ot1-x33a.google.com [IPv6:2607:f8b0:4864:20::33a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G7fGF5pLhz9s5R for ; Mon, 21 Jun 2021 16:08:04 +1000 (AEST) Received: by mail-ot1-x33a.google.com with SMTP id l13-20020a9d734d0000b02903db3d2b53fasf8680169otk.6 for ; Sun, 20 Jun 2021 23:08:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1624255679; cv=pass; d=google.com; s=arc-20160816; b=QpaNcL6DBzI2fYTkvTUHDjQO/fygdO4VDCEsXkoAJqkFE4fNXBFEP2a2dD1wWg+fAB td4Eq0CWLcEcOWkeTp2WTB1QRyTENLCTSiZt+kd7E9fX29qg9bvnAyZCaG8GteQs0cMa 06U6Pra33rxtsdQJ636ew/dj4v/9xpK8Gnvo8HxOKo3xkObgkhYbDJ3DPfmdFve8Pz6Q f+hrEN7b8yRFYP3Zh88Bm3BkVu4URJHuvsuVNQ84whYsopVi2SqTFfOZ0z4DqB8DpSAl WWQX/vyZUkP8C6OjyUDhx0tajjsFp28TF4LTh3jz58rNk965wXauKuBcw5y3W54rMMC/ vVCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=EiJDPwlTd143ElHY8aoSzQTb00DEYjWVIFL6x7ewwww=; b=taNlFJXIga7erEDBIhFORJFdF17WTbZgCqeSLJVkiFTM3Cv8k+Pe7VEvKdfoJN3evI 9EteyHHRE4MSG6VxECQIbNrM82LR3xihv8ozqQtVMb+Vc5f8/5WwMhAgRKXw+zYfnf7w 0eudShrKsPdQ/qpjx+Zkm8WcHGk5gzZb4L0+PrzG9Ogmkhw5Zse4odADMIYmpdNwPQJK FK8GB/9Nzhkj6HB5RaMiUZhLouf19o/B6cdjPalSSVkgqD+uIct7NzlIGz8fMMcMhJgR xvj51BDNSbUncAj3J31yv8gPZ61Tgw+tE/imKtEIyub5nU/88xSKQbL8hKmT6Owmkexj HaGA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=EiJDPwlTd143ElHY8aoSzQTb00DEYjWVIFL6x7ewwww=; b=blpTotyWZOj/T2K1pv4nwTt2R6pKLG52qRPGk2os8/yEhVM8RMN02XalzbF8ONMTxK KkNKUuNsyK232t1UxJHHvA3Voz5zpheAG2R4AH+rDrksRZywA581mx5EvdRc8Rqh/JB0 F5SwX74zK6oUzYHWLMGUX8OSk9xiOmimyQThoaEql2ujWRXPp14QvCkFSq7n1hTCYg6D lKDJeyErKlmANppaLhzoHTLnn3A7dg/fl/TcmvFfQty1d8hpqllBiQ6T5Ak++VZTAGf+ gz982Dk3sxOi3woBgmJtGHUDae2vuVooAO1GjiHBdx1aeVjXbrZzApTDUa2z2OPk0PMo X01Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=EiJDPwlTd143ElHY8aoSzQTb00DEYjWVIFL6x7ewwww=; b=mX/80GbnHCTNzCcpC0ZDQ5zJvcSYZT9CG/hVmL9kLeo/J4eFTU4RVoti9WvsmoAI/M LTgaG+tVql8rpXb8DXUXiUzTRp8cI5Vm7SoYrmSipDVBOtH8B2oMl0V92k7cIeoJmPTe 3c/Q4TWowlRr7/BLfzFw/kKuWvrmNtt7LqQnFn3LLdtTWv6ODFjE2Zk+W4g5ehYhiYcU 12iADzgtPSoCtx9iSXf1lwLM/8vqZrgNDl1jRXEZ3TeBi9+lUClogMyTcg3ifFAiVzoH aBnZbEWQu4XjwkiU64IBbJc62LHodPqxhExGBXPqChX1ypH9jZ948lhuvuF+Y/mzrSQv BAOg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532+64nntj2/+OP1CbGWsklBHdRw6GKbTgl+11jTQS/wkXD4jSio bRxcSkaHIhF9xveRJjxQlJg= X-Google-Smtp-Source: ABdhPJwoHJQv8vdVZFa9h4ag49UXXhtxcW4VfH8F4Fe2WgOrJLO/uY/btIrZusTw7qalOLKFEVKwiw== X-Received: by 2002:a9d:5c16:: with SMTP id o22mr19916950otk.319.1624255679415; Sun, 20 Jun 2021 23:07:59 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:aca:5a83:: with SMTP id o125ls5755073oib.7.gmail; Sun, 20 Jun 2021 23:07:58 -0700 (PDT) X-Received: by 2002:aca:ab15:: with SMTP id u21mr23421594oie.50.1624255678794; Sun, 20 Jun 2021 23:07:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624255678; cv=none; d=google.com; s=arc-20160816; b=02yoOJ6xItb9z/vR8avEd5Fe0FNFbtBL+93lTVTcdbiJ+ARjiu9AM+2JzmkcdJBSTB XYgoB/gvltFaKuymjs9Bnm0W38O/kgspjtOalq8NgUXLwQ/ZjpBvfoT01IAukoe/jNwW C47/Mj757MW2n3zBNg/yGp99Iq02sY6yhCqBhcrFvxoBPzV8cjwJkwJHRB3jR95i6iKN 9qRnRBwd1Bhyn0Geiy06DbYlcPsx1Yv0tfsirGz1ay/gVBLI2A59KHwUAERdkqTxMijx V46EPOMNhw5MhbFU3AD9BI68JFhN2PikZC5gd/6TshzJfsG2Mf9lvbI8ddkk3Vnv+imt O0SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=s9zALMQ5TCmHyAeww2q9CpjW7hArSb4OThqJq3Lk1Ck=; b=BU3oaEfMzFB51QxI6+q41H4joSboXNl4fmfidRqbYisIFxgidR5kPnRQZsZTAO5bWl 8E/HX0YaTSmy2bRPPomlDbvbj+OSZM/k0VII1yBr8vdr+GvMs+xK2BhGiXERdROX1JLp kHIt8sg8LVc6IqDCcRY5nMJ56VdX3lQVKARlpnnTYBplULF8tjgS0FnUTIpe9SOuH3Qd fN8Zx5dYLuHQxQwhcbNFJcz06ULBg7xFbNQT8T4fc/NSB//1MKGO7/9wS4mhJZTclz2X fgD6pXP/tnG81RhB02n/tHYDRuvSOjl5mc8tKr9wfa6/RzKa0jRrvHAansjtH9ohOGdY oNYQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id k18si2069519otj.1.2021.06.20.23.07.58 for ; Sun, 20 Jun 2021 23:07:58 -0700 (PDT) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id C237020D02 for ; Mon, 21 Jun 2021 15:07:56 +0900 (JST) Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by gw2.atmark-techno.com (Postfix) with ESMTPS id A8E6320D02 for ; Mon, 21 Jun 2021 15:07:56 +0900 (JST) Received: by mail-pj1-f72.google.com with SMTP id w13-20020a17090aea0db029016f87715355so2909060pjy.5 for ; Sun, 20 Jun 2021 23:07:56 -0700 (PDT) X-Received: by 2002:a63:5005:: with SMTP id e5mr22493697pgb.340.1624255675819; Sun, 20 Jun 2021 23:07:55 -0700 (PDT) X-Received: by 2002:a63:5005:: with SMTP id e5mr22493679pgb.340.1624255675571; Sun, 20 Jun 2021 23:07:55 -0700 (PDT) Received: from pc-0115 (178.101.200.35.bc.googleusercontent.com. [35.200.101.178]) by smtp.gmail.com with ESMTPSA id 35sm13889583pjo.16.2021.06.20.23.07.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jun 2021 23:07:55 -0700 (PDT) Received: from martinet by pc-0115 with local (Exim 4.94.2) (envelope-from ) id 1lvD69-001NTL-AG; Mon, 21 Jun 2021 15:07:53 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH] read_lines_notify: fix segfault if a program prints a line starting with \0 Date: Mon, 21 Jun 2021 15:07:48 +0900 Message-Id: <20210621060748.328497-1-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , if a program prints something starting with \0, string_split will successfully allocate a string array of one element which is null (so nlines == 0 on the next line) There might be other problem with string length (we know how many bytes we read), so instead of trying to work around it in all cases just replace all nul bytes with @ like we often see in e.g. less. This can be reproduced by executing a shell script that does e.g. dd if=/dev/zero bs=1 count=1 Signed-off-by: Dominique Martinet --- I wasn't sure which way to go between trying to check for all corner cases or this, but read_lines_notify isn't meant to handle a lot of data anyway and we're not either retransmitting things verbatim (due to info/error header) so I ended up preferring this quite a bit. Please say if you want me to just skip printing nul bytes or something else. core/util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/util.c b/core/util.c index 3b81c091b0e0..ebeb8587644e 100644 --- a/core/util.c +++ b/core/util.c @@ -1001,6 +1001,12 @@ int read_lines_notify(int fd, char *buf, int buf_size, int *buf_offset, if (n <= 0) return -errno; + /* replace zeroes with @ signs */ + for (unsigned int index = 0; index < n; index++) { + if (!buf[offset+index]) + buf[offset+index] = '@'; + } + n += offset; buf[n] = '\0';