From patchwork Mon Dec 3 10:42:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1006798 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23e; helo=mail-lj1-x23e.google.com; envelope-from=swupdate+bncbcxploxj6ikrbfmrstqakgqeov6cnji@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="cGVOemYq"; dkim-atps=neutral Received: from mail-lj1-x23e.google.com (mail-lj1-x23e.google.com [IPv6:2a00:1450:4864:20::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 437hQd5m6Wz9sCs for ; Mon, 3 Dec 2018 21:42:33 +1100 (AEDT) Received: by mail-lj1-x23e.google.com with SMTP id x9-v6sf3532493ljd.21 for ; Mon, 03 Dec 2018 02:42:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1543833749; cv=pass; d=google.com; s=arc-20160816; b=N8qkN77XzoF8xC2LqfnSgIJi9Puoue+nBWMlyh/3CIFh96jFj4g9CnQdMy1WTznoGz 7jiPIs9qV28sH1XWR65FhEojdEM/0EzzGVt95o3XPynOIWKd3fHg4E0S52nqXO93a7j5 iIlJ0JJ/57h5VspJQOkx1qYh4eOS4U2qarTe30owF48Q3cIOPpkcWHaErPYXbj63fG4Z ysZC5UNvt6ScpVqqhUnbylQvscPXiLlFr547Quhh+14fsJdZLGBpOlqRNfUnU8ts0HNi EIWMJPsAwr9nYu4BwbCM2o0+c0SM4xLyfD4Zpo4pxNto+ZFFYvutSpUU6cWvwVUBYPQo GGiA== 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:message-id:date:subject:cc:to:from :mime-version:sender:dkim-signature; bh=bC4WHdDflOK1BgFgQC81GfMtb7XJhvv3a0HNl9Q+m1g=; b=Vg8t0Ugg3cOyTmqkKOkJKJ9lLNijkSDqw7GA+TL5m7ldbrc8Nj+Ai2QGwcqgiS6F20 Uceh4M/KghT4v+i23yZGXMfWjJ31Ni3GkYoz4DdWFPPDCb/DuNugW4i73XQeeNvLdNDn WQp1dYfY2pLDSqXU4SpFmnlvIiS0Ozow6w2CcETvpi2patRVpSYJlTF2DJixEf/3wX9G SbAPAOfn106fEQ4LSlMDZRHuEldueO6S+/ORMcQbFEdJtgNbfJhlnC+gwFkxS5qUtfmU bS9Yi3jjPoNsKiCfbtQoGxmCzLrGmSYdpGpBLnapgCvQHqX1hO8XLCzWmtODv5u4zlzX 7Kig== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=bC4WHdDflOK1BgFgQC81GfMtb7XJhvv3a0HNl9Q+m1g=; b=cGVOemYqELSxt3mmx9vsAyUyUeKEU8jHe9xSk81Fyp5G7q39KmWk12bP9B01ePH4i/ oLaStl76hL0aRKz7cMk0/TbuAv7tSJZVfNzK3fICIqmg7kVKEsSB5bkP8UaK+rzmvrOS qZwK9pI+oSYR98XcnHBmb9JqEhLSVZqnJKlQLI1wj9dlkVhGownVQhhFCNKA41Y+Vb0l PmHahfJWVPMc2T1aHZY99MOWvikb+2mhrvo9meL0f4Bq3lqHUjlaZ6wZ5ba+inSvF/Qq 80f3DkpWXkHPxtxURHZ5DIv/TKjkUpjIcSDMpCttEWFUvVyMzQifCEF2uGobpjsrd7jq ZMJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id: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=bC4WHdDflOK1BgFgQC81GfMtb7XJhvv3a0HNl9Q+m1g=; b=QLLbIA3Q8vNBubQ4R7nA+y1XGFS9E/xyygSrcGpwEJPA+92SbPDmfw0bHluffIDaZy kfKjFdbU0RRrY1Oc3IdKfu+UvU/eqYgtqmcs/lYCvexWl6btQHY/52uz8rS1s9zxMHEX 8XkoAE4OeX7dlJxsW5q4/h9aXF3umCm7H66UCsaP/HixcEZqW5nIj+59DBW4Cj5B4uWI QzK5pxWXh1Q7QZH+ce8JtlVBu2kBjgqyE5yXma1gU/GFJiFMravz0UVQkMRJGanHBP/g Qz+gvjySaUl10RiZhpTIorrcUP7jyDA5spypurDb1QxwB71ZV8HsQcwwkvjRehe9uZIZ Gq7g== Sender: swupdate@googlegroups.com X-Gm-Message-State: AA+aEWbX+C2aIUFtcsvwgkFUqcAWzJ4wR6/valKtNXNBUoxmlsTRR4Sz 18NX4yHDbnHn9qDnfYja0gA= X-Google-Smtp-Source: AFSGD/WP707Fnk1IZ/PGvO8argqVIc+0zuiU5C8KDOboogOhX9agFYBFIW/PeYb4lkP/gC4xaJyIkg== X-Received: by 2002:a2e:90d8:: with SMTP id o24-v6mr106802ljg.5.1543833749517; Mon, 03 Dec 2018 02:42:29 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:520f:: with SMTP id m15ls1195715lfb.5.gmail; Mon, 03 Dec 2018 02:42:28 -0800 (PST) X-Received: by 2002:a19:a245:: with SMTP id l66mr1156276lfe.0.1543833748667; Mon, 03 Dec 2018 02:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543833748; cv=none; d=google.com; s=arc-20160816; b=lp/HKrq3z1sjiYCXIQHhEmHZ+qTPAaNTcxgUo2AJby8uiQavbSz8N1Oh3H2G4HxVXY dTnaHEscGgixPn6VWKIa3igabG6kvpe1ThZ9P0VTb3phgzxBhWYJzSwERzBxvTma9XGV yj8zw85vVFknOH9yy109lKbHKwoDUSy+KyS1UaaGrHedBTH1bWVwvFKiXFmhl55U28fZ CmrUT/NEcCDIxE3bQaGgP0t6K37nsvoUvdtdlv16wqV0SPhgFACwq5SxiIi1SEUE8aZB nkVRR6kP6g8dGpRkpy/iFjqwnkVLfzn1QdOZWEWgkYHhoimWrEPKvLkXztJqa8dQ/O0X 72oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=uH0D76H07JMjA9NTK/WjjhMS4Mf47LOIPoYWCou/u58=; b=MLlLRL3Fn634b8wIxverrhuMmbSW2n/fwkCym1SHvPZtchLJ+SzeW6bAhTTY30imUy oWRlZotpgj+bCL6m6j8AY+suNAGPUEGGBIuBCin1SthcfSLxY7NyXdf08dGYsIQabWvt 4Dis3P9u4Who728+3QwmNyPdf87qO8klyPBu1vtL1252EFw6JmfobNOag7CNbmifsa8f FhBxUEhARYIyV5D4+aQMFwRhU6IiD03tWFV+ONdUwc60BR4F6qz1BWNvuKorDUzTux3d mLrux4vL966ZdJZmNYJ/DBeX3hkklwkZNvwEdDTeKnn/2aoYR3hB/gQiuf2vZEBjpJwP o8Pg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.10]) by gmr-mx.google.com with ESMTPS id h17-v6si503327ljj.0.2018.12.03.02.42.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 02:42:28 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 437hQX0Sg8z1qxDl; Mon, 3 Dec 2018 11:42:28 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 437hQX0G48z1qw67; Mon, 3 Dec 2018 11:42:28 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id xXfnkBOJt1jm; Mon, 3 Dec 2018 11:42:24 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Mon, 3 Dec 2018 11:42:24 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 2DF6C454035E; Mon, 3 Dec 2018 11:42:24 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yZULgMclxk1X; Mon, 3 Dec 2018 11:42:21 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id A080D45402A9; Mon, 3 Dec 2018 11:42:21 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH V2] handlers: bootloader: let comments and blankline in image Date: Mon, 3 Dec 2018 11:42:18 +0100 Message-Id: <20181203104218.19797-1-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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: , Allow to insert comments (line starting with '#') and blank lines for bootloader images to increase readability. Fix crash when blank lines are part of the image. Signed-off-by: Stefano Babic --- Changes since V1: - fix crash if the environment file (image) has comments (support comments starting with #) - variables not correctly set if they contain a "=" char handlers/boot_handler.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/handlers/boot_handler.c b/handlers/boot_handler.c index 29fd190..2a1b61a 100644 --- a/handlers/boot_handler.c +++ b/handlers/boot_handler.c @@ -73,12 +73,43 @@ static int install_boot_environment(struct img_type *img, while (fgets(buf, MAX_BOOT_SCRIPT_LINE_LENGTH, fp)) { char **pair = NULL; unsigned int cnt; + int len = strlen(buf); + + while (len && (buf[len - 1] == '\n' || buf [len - 1] == '\r')) + buf[--len] = '\0'; + + /* Skip comment or empty lines */ + if (len == 0 || buf[0] == '#') + continue; pair = string_split(buf, '='); cnt = count_string_array((const char **)pair); - if (cnt > 0 && strlen(pair[0])) + switch (cnt) { + case 2: + TRACE("name = %s value = %s", pair[0], pair[1]); dict_set_value(img->bootloader, pair[0], pair[1]); + break; + case 1: + TRACE("name = %s Removed", pair[0]); + dict_remove(img->bootloader, pair[0]); + break; + default: + /* + * If value contains "=", splitargs returns + * more substrings. Then pairs[1]..pairs[N] + * should be treated as single string for + * the dictionary + */ + if (cnt > 2) { + char *tmp = strchr(buf, '='); + if (tmp && ((tmp - buf) < (len - 1))) { + tmp++; + TRACE("name = %s value = %s", pair[0], tmp); + dict_set_value(img->bootloader, pair[0], tmp); + } + } + } free(pair); } fclose(fp);