From patchwork Mon Feb 24 09:13:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Aguilar X-Patchwork-Id: 1242906 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=2a00:1450:4864:20::53c; helo=mail-ed1-x53c.google.com; envelope-from=swupdate+bncbaabbn5hz3zakgqedgqjerq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vimar.com 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=OpQnR8Ka; dkim-atps=neutral Received: from mail-ed1-x53c.google.com (mail-ed1-x53c.google.com [IPv6:2a00:1450:4864:20::53c]) (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 48QxF80xmdz9sTM for ; Mon, 24 Feb 2020 20:13:31 +1100 (AEDT) Received: by mail-ed1-x53c.google.com with SMTP id dd24sf6247262edb.1 for ; Mon, 24 Feb 2020 01:13:31 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1582535608; cv=pass; d=google.com; s=arc-20160816; b=TUks5+FP1FHxJylV/a3NPce03VkR/GvdFqTdker25vEe/f6MhQmQ8PbPe249hBYzLA NGfCG4rNco6oXudschLHtwSJOX4dE5DNyUsVHOWZT7tcMy8sctUj3vQrwdDk7yB4kkqU V+SZw3H3keHWh0hG3+g6ks797MIZJcw3pz6ATSZc+SFo4lM4dIDxPXkrOTX5pKzX65rL cIv+JuBr1FM7UJWFOQ5FHXcawfFfJpLRS/mScWTnALVCC/Hqf3HWyYLk64JSh0eGuwRS fbTyQmfL79AN/jk0iGiD4DavciiHAhVREBSWNEDzVYoJ7lAcVIFQ/k6zAMOM/Wg2890L ZjKQ== ARC-Message-Signature: i=3; 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 :content-transfer-encoding:content-language:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from:sender:dkim-signature; bh=F0IOde362Ft70RqPNjLrOJ+ERUmq2gxhcZogYa2raLo=; b=ZC25xGVkA3en2P7O48lMeWm5JfnGW81AW+EsruQS7vtW50n/KPLkwTihELZc7vjzQo 2BBQqB1JAKYMhbyCtw12nAUJOVTMNVHcksfazv64uqjM+3kMw7e02hRl3bAvU7V1MEZB u9KHNNFjVb2Z0nkhWGYfik//AM8H2FAqJDSZwovwEqPEVjWp8rhEnPZvAvIUGLjk9mPi zQXLCQZHP3axocjc3l2nBJE12KIommYuzRdyHKUOhLSuFLo4nZLUUC98lxlmSQA2wvRK 9/rnFu+c3zF0wCJDDawWom3Dg0w7duf9dnb34v7+MWQqsXxBZOVmECHR2P2p6U+PuSkc m2HA== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@Vimargroup.onmicrosoft.com header.s=selector2-Vimargroup-onmicrosoft-com header.b="N/wjaaTL"; arc=pass (i=1 spf=pass spfdomain=vimar.com dkim=pass dkdomain=vimar.com dmarc=pass fromdomain=vimar.com); spf=pass (google.com: domain of pedro.aguilar@vimar.com designates 40.107.4.72 as permitted sender) smtp.mailfrom=Pedro.Aguilar@vimar.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:thread-topic:thread-index:date:message-id :references:in-reply-to:accept-language:content-language :content-transfer-encoding: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=F0IOde362Ft70RqPNjLrOJ+ERUmq2gxhcZogYa2raLo=; b=OpQnR8Kam0IaDhF3atD7mFrOr5gjdmgz3X3t9PGVeUk7RVMCH3b+jqX6JhRbMDaYMv 6893nnWHTbshFeeI7RIRQFe8rKHkaD9YG70XsfG9VufrVsMynCOqJnfKGRZ/FXwqvkm/ PFqbYJJXugHHwiyLFWV2Od9DVdYdMDCiFU5rCWggVPJZ9UodS/GSF66GSDZN9QIjs5FT zAr2oXBlf/Rj3RaqpG8GfFzM/9hdVgkV334LSut1Xs079iYG05b3CdJMbzvW2oTAhg++ x0DubTsngaQzIz0Mu/wysEXuI4g1qpX5tqjBxZDBwOJFUjGnJaU/FBJ11Fk2zM1dHe4Q 5fJw== 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:thread-topic :thread-index:date:message-id:references:in-reply-to:accept-language :content-language:content-transfer-encoding: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=F0IOde362Ft70RqPNjLrOJ+ERUmq2gxhcZogYa2raLo=; b=PTILvgLoGLcl5fUG5ZRxiZ38CceErZWmrHbgH0CJTGrgzzEQr9Twjenn+4qO59lHsT n58AkQd530bP2+OK+ikFX0wqxnf1IfcIsBfQuSdo61L3oI2TdL7xXhovv4d1kRoB6uza M81aVVB6HhxHp9JvnzpL/f+t8YH5G/YE2IX/asfVyl2lwJ5Sk7T3Zx6WRD014sFCkqaI yo5CtCIVtBCmXom1/IdojtJ8AwUEbgI5L2z31YqYSSaFoQUUtXvHGv9eZ8fOudq6G5os 5kA90if41WwRKvSxgj2GpR7bM6Kf4HsgY9c5fLYUyqhsdgKKgBKZpEQvTclbfIafjWK6 KVww== Sender: swupdate@googlegroups.com X-Gm-Message-State: APjAAAX1/7ans5aQV3zIrQwn5yuaMp7WopWxMQHKXmzNFOeRsOIVgtAo PaWuipz1AXKc4AwGyL1TnOQ= X-Google-Smtp-Source: APXvYqzlqpV//bl/Juvf+mZv6z2t71smIPITVLExwd+5SFlUahDkqMAL7rutLV9A+rsVDUSwbg4uqA== X-Received: by 2002:aa7:d505:: with SMTP id y5mr47507667edq.370.1582535607964; Mon, 24 Feb 2020 01:13:27 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:906:6a12:: with SMTP id o18ls3763323ejr.2.gmail; Mon, 24 Feb 2020 01:13:27 -0800 (PST) X-Received: by 2002:a17:906:716:: with SMTP id y22mr46596287ejb.106.1582535607425; Mon, 24 Feb 2020 01:13:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1582535607; cv=pass; d=google.com; s=arc-20160816; b=th87UqGYdrf4L51hr0xxenR6fNoPQQg/opDKHRTz0/aolh0WQBNH1tflbmTnuLzPhU Ae+I7s+VMEmJs2mTJdpYDiuvxbFHYhZMk+j3vvf51u+J6rz4nK3gOyeacwEZSFemQ6cL 0/gV2WR+6v5NE7AYkRzURkhZAsjYT5zQQ6UA/2498q9mHZ6eFSIo2L8IrEd8FPBuav2F Ksk5xPgdrqV0gQGVooymXOtcpW0PfQaIBXSnm4e0ltavSJtNFyDrFIq9WHCrsTO328f+ wKq3dXVn2938o0Gm+syI8P/BzJbSnbLVmUTM5yB1X6e9oQMlvjprFqWRA560BeEDDvPb 96wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=jiDyiWF+do4GzYyrzaV5bzjBYo4xKnDALXRZBjFUdxA=; b=EScQzCTOkPdV0fli4rcjFQCYq1B9BDOextIbu6cKaFF+abEWX07VVwnSnJm6t3RGAV Eq39JLEdPYkuDAamOMu8AvMteiUfkO4KnSVmLvwXj9WxnUgZ+b4vR/Lg7TfO3RSIvFLS SdUvCVa9JWGmCJBLtiTSrW9zXv8gEP1Wgd4TLJJLndyi4/J8sTvfItgGqp/Kypk9cbnX 38lBYBXH0IFAL447a5Bvy3YX/190l0A6coihmTviMiT4tLDlkG+YOwqdkNI+s2aeWYtU xy/PXXQOZTAJ/03kn9VtGUhOmz3hPZOUYtgb2qUgHgjroOMsKND9ruICOrxNsf8MQusj QZjA== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@Vimargroup.onmicrosoft.com header.s=selector2-Vimargroup-onmicrosoft-com header.b="N/wjaaTL"; arc=pass (i=1 spf=pass spfdomain=vimar.com dkim=pass dkdomain=vimar.com dmarc=pass fromdomain=vimar.com); spf=pass (google.com: domain of pedro.aguilar@vimar.com designates 40.107.4.72 as permitted sender) smtp.mailfrom=Pedro.Aguilar@vimar.com Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40072.outbound.protection.outlook.com. [40.107.4.72]) by gmr-mx.google.com with ESMTPS id n1si925697edw.4.2020.02.24.01.13.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Feb 2020 01:13:27 -0800 (PST) Received-SPF: pass (google.com: domain of pedro.aguilar@vimar.com designates 40.107.4.72 as permitted sender) client-ip=40.107.4.72; ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DvHHZ05f9JbeDVhLd8vbi49WfxlcDYTIk/bjPOw74tD5ugeTJlgULcK/H07K63edpv/k+gAg80MFn+Gn5MvmWFl0+HsygqUE9qxf1xk9cawrsh8h5yX+ZOHT3d+1ND4N96nOYZBT5Gon2rCoKMpl/bc1A8ZBv2i8fxRPc6EpVS8Dd+z9SoQezw28WUaEekjk/Q8Yg71qb5OtJT444BGT75fyrlaAY5HSw4kV96J6zxXG5P0aNpUckAjgzrZNn1Nw6x2PNEu2Vx2ggzq0Q/7Q83UrNMUwIzg+ja4vuKh0Hyk/QJQ/19v8uY2HLpa99iIEjyvNRmGrtz6ozuQRpzi2gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jiDyiWF+do4GzYyrzaV5bzjBYo4xKnDALXRZBjFUdxA=; b=EMBiV3Ya5XG3QLvY/o4utxy6+n1bkfZWDrZqPChGM/tP0AP0f915cbU+JWCW6qH3vavciss/xDFRtPyxWxDHAHGveBWPrOLrvVxUKTT/btrnVVEMw+CMm/RQBIFviZBZbwXq8cb/KKYgd1s5hMz3+FfdIhnkW24V6oG1yiiQEnr+cGDYlItvULGi7T3ByTM2fGvMKBsOpAlPLw9hiUDZ3Kmc5scTpHYT+fu7JWMbH29blFCzwt2o0Vj+K+4sZmKaZeuzBks2mUcCHULuQuXcNVvwKVwmPU5rskUDmGn8SawzYpqSgePWNjXqcV7FxFd+V8Kp5gm67UXDLIkPSzKjbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vimar.com; dmarc=pass action=none header.from=vimar.com; dkim=pass header.d=vimar.com; arc=none Received: from DBBPR08MB4363.eurprd08.prod.outlook.com (20.179.43.138) by DBBPR08MB4267.eurprd08.prod.outlook.com (20.179.42.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.21; Mon, 24 Feb 2020 09:13:26 +0000 Received: from DBBPR08MB4363.eurprd08.prod.outlook.com ([fe80::7405:9ed7:3ce9:26ed]) by DBBPR08MB4363.eurprd08.prod.outlook.com ([fe80::7405:9ed7:3ce9:26ed%3]) with mapi id 15.20.2750.021; Mon, 24 Feb 2020 09:13:26 +0000 From: Aguilar Pedro To: "swupdate@googlegroups.com" CC: Pesce Luca Subject: [swupdate] R: [PATCH v2] stream_interface: Keep reading the cpio padding, if any, up to 512 bytes from the socket until the client stops writing. Thread-Topic: [PATCH v2] stream_interface: Keep reading the cpio padding, if any, up to 512 bytes from the socket until the client stops writing. Thread-Index: AQHV6vIi2H+lxXhKeU2L925do9juzqgqDyJt Date: Mon, 24 Feb 2020 09:13:26 +0000 Message-ID: References: <20200224090044.4373-1-pedro.aguilar@vimar.com>, <20200224090840.4589-1-pedro.aguilar@vimar.com> In-Reply-To: <20200224090840.4589-1-pedro.aguilar@vimar.com> Accept-Language: it-IT, en-US Content-Language: it-IT X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [93.62.232.162] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a8ec927c-3c46-4424-5937-08d7b909ce69 x-ms-traffictypediagnostic: DBBPR08MB4267:|DBBPR08MB4267: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 032334F434 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(39850400004)(366004)(136003)(346002)(376002)(189003)(199004)(186003)(26005)(52536014)(478600001)(9686003)(6506007)(71200400001)(86362001)(55016002)(7696005)(2906002)(66446008)(5660300002)(66476007)(107886003)(76116006)(81156014)(33656002)(8676002)(81166006)(8936002)(66946007)(316002)(66556008)(64756008)(6916009)(4326008); DIR:OUT; SFP:1101; SCL:1; SRVR:DBBPR08MB4267; H:DBBPR08MB4363.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: vimar.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0ttN6NXu0XwtOZHTlpvj+xs0dYKZ3Pof9P7BSJ/wQQqI9nEH47Tv7QZUVTWYE6zQfDV5oUmCBpg1bKB8Qu9GJVdhlMpRay7YGBakpqzwnRPgKnOJPkDXY/jhi6dmdimJJNVGAj1YqedMxhpfv1f6DBc3gOk7SLKc+Xm+tzOtFFkX1h87K8HvPk/Qju8SONjVuouCb9M8H7IjKXp2Q0kjRrIxIB52KyDVSld0BPdkHo67c48RgyRkNWSUNZZO3/uNKOl0ay9Ed8iavnNEaM1/r/3hoTd7gOykAZ3sKxL+d8UCtG+DCwx9qZNXHKsmRKvRMYcG7rqTg4NLux0MC9DcTWNVg+UmQLr65lTn7lWx9ZzThW/iRbPMvyMZq7IxOatrGubhDsxJ8c1QpW7kFz002K2hTbqhgV7/STxLFTldY1Mc5JJFIlF3BE19QtCOxC0X x-ms-exchange-antispam-messagedata: 2509KUX1d4biOXCtrcEwxNqsfFUe3hWalKPnW3M/1lybJFVmCJ2AE7ulbSSatc953Z7JM7FBRZPPCDNWxj8hxsHboUHSLYoHgx0xk7yZuruSI4XObNupGkf2VAkH47Wxmo5Bqof5olL2ae5FwIHiNw== MIME-Version: 1.0 X-OriginatorOrg: vimar.com X-MS-Exchange-CrossTenant-Network-Message-Id: a8ec927c-3c46-4424-5937-08d7b909ce69 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2020 09:13:26.3110 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a1f008bc-d59b-4c66-8f87-60fd9af15c7f X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: /YbYZXiq5oNe6BRG1ZVWGIBQCnw6Y5hoGscwBWegL2DQ3G3ZnsHs8Q+xrTgKQi13Ly7cT3EDiC0/qn3uGJkRCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4267 X-Original-Sender: pedro.aguilar@vimar.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@Vimargroup.onmicrosoft.com header.s=selector2-Vimargroup-onmicrosoft-com header.b="N/wjaaTL"; arc=pass (i=1 spf=pass spfdomain=vimar.com dkim=pass dkdomain=vimar.com dmarc=pass fromdomain=vimar.com); spf=pass (google.com: domain of pedro.aguilar@vimar.com designates 40.107.4.72 as permitted sender) smtp.mailfrom=Pedro.Aguilar@vimar.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: , Hi Stefano, The above patch follows all your suggestions except the function extract_padding() that remains inside the file cpio_utils.c since the 512 bytes padding is a cpio-related format. Thanks. Regards, Pedro Aguilar. diff --git a/core/cpio_utils.c b/core/cpio_utils.c index 03776e2..8cf4713 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -79,6 +79,32 @@ static int fill_buffer(int fd, unsigned char *buf, unsigned int nbytes, unsigned return count; } +/* + * Read padding that could exists between the cpio trailer and the end-of-file. + * cpio aligns the file to 512 bytes + */ +void extract_padding(int fd, unsigned long *offset) +{ + int padding; + ssize_t len; + unsigned char buf[512]; + + if (fd < 0 || !offset) + return; + + padding = (512 - (*offset % 512)) % 512; + if (padding) { + TRACE("Expecting %d padding bytes at end-of-file", padding); + len = read(fd, buf, padding); + if (len < 0) { + DEBUG("Failure while reading padding %d: %s", fd, strerror(errno)); + return; + } + } + + return; +} + /* * Export the copy_write{,_*} functions to be used in other modules * for copying a buffer to a file. @@ -760,7 +786,6 @@ int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start) int file_listed; uint32_t checksum; - while (1) { file_listed = 0; start = offset; diff --git a/core/stream_interface.c b/core/stream_interface.c index ff2f6d0..824c51a 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -174,6 +174,11 @@ static int extract_files(int fd, struct swupdate_cfg *software) return -1; } if (strcmp("TRAILER!!!", fdh.filename) == 0) { + /* + * Keep reading the cpio padding, if any, up to 512 bytes from + * the socket until the client stops writing + */ + extract_padding(fd, &offset); status = STREAM_END; break; } diff --git a/include/cpiohdr.h b/include/cpiohdr.h index 855d5e8..aa1c9b1 100644 --- a/include/cpiohdr.h +++ b/include/cpiohdr.h @@ -53,5 +53,6 @@ int get_cpiohdr(unsigned char *buf, unsigned long *size, unsigned long *namesize, unsigned long *chksum); int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset); int extract_img_from_cpio(int fd, unsigned long offset, struct filehdr *fdh); +void extract_padding(int fd, unsigned long *offset); #endif