From patchwork Tue Feb 7 07:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1738765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=OdDqrgRV; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P9w172sfLz23y7 for ; Tue, 7 Feb 2023 18:36:26 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pPIWX-0002Xs-QP; Tue, 07 Feb 2023 07:36:17 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pPIWS-0002V0-3x for kernel-team@lists.ubuntu.com; Tue, 07 Feb 2023 07:36:12 +0000 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id F022F3F2F9 for ; Tue, 7 Feb 2023 07:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1675755371; bh=6FgACsIpJa3GsjiGrdeu4Pl+ORRZntm5M6f2GtL+0Zg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OdDqrgRVOmbs1IGjrLabkTyEBAhYjCUXGwLw7YBp48bj2NTyN5zv+t8SakKGggCKJ 0ZZnr7GyWE2VvYqz0jshYfL48q2lQwfQOxqSLLG5F7mbNGISmLCatWgq5wS5C/8wbi Uf1iVP/2vrYL0LGzBu/SW3Oi3DA9oGUFY1HMrGeD9KbiFftUgKmi2gECutbVno1VXW AN9bsz+lPU7SSIBMQdPRhJf+p2iLCBlWR8cgld7z3P9VqM4RTRwo/VHniDPKWo1Xqc b6ponHfHZnS11e0PGtYdvtqspgR8F24Ds0iYaoItOnZKFoFxXLSf0ESCG11eE83QnA G6WhBWZ/rFtgA== Received: by mail-ej1-f71.google.com with SMTP id wz4-20020a170906fe4400b0084c7e7eb6d0so10491560ejb.19 for ; Mon, 06 Feb 2023 23:36:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6FgACsIpJa3GsjiGrdeu4Pl+ORRZntm5M6f2GtL+0Zg=; b=ySOcj1ajFz0E+KbC3KLUMdAUNZapVkLTosBL8Q7e6x3tGWjtZtxxMls/02MVaxoN5L uFkvCoJ31V41PSHSK2kkjqZ1wU+FGAZIMo7nzU3JZYzb6bPp5KTfpvahl+MdDu+wf3GP zwGK2Rc/GBYcdnMAKX2Dzpepkmr9pbB7yxiEWDcKIqvRj5nJCwpw6VpIfVjJvrOWxvAE 7/at3LAaklyTF4EaWU795dFUg8EkGk/bbgQt5/f/9Z4u/xoo2ups53Z+4ilUKOljmEMH K6GH3hrU3zYijQCiy1jugj/tvA97KNHA9aT1xjZLsbe9rOp7EIk0xKX7aqkhO129mpC0 Wffw== X-Gm-Message-State: AO0yUKUEizStCv2Z3MkFeDlCqAf439cIuio7xOnOalnt84j59tVtSXif QIWLVW5PxDcv5Znxk9bQjPv4r26UKG28jzYfo1YzYU9QaiCf62iN+wnYqyQN0MivUskzsz8ov2Y 1QdeMepqP9yHYWSn+5Rx8Lkm2O9jko3iKXQNI6niOLypIJpU= X-Received: by 2002:a50:c30e:0:b0:4aa:a968:ac94 with SMTP id a14-20020a50c30e000000b004aaa968ac94mr2507455edb.3.1675755371640; Mon, 06 Feb 2023 23:36:11 -0800 (PST) X-Google-Smtp-Source: AK7set82MONzC9cftcbfrHmk58DZSNqx8AliBW+yiBkg13UaQXN/B3RzgPjl3l8bw5uKvs74FyEEXg== X-Received: by 2002:a50:c30e:0:b0:4aa:a968:ac94 with SMTP id a14-20020a50c30e000000b004aaa968ac94mr2507451edb.3.1675755371481; Mon, 06 Feb 2023 23:36:11 -0800 (PST) Received: from gollum.fritz.box ([194.191.244.86]) by smtp.gmail.com with ESMTPSA id fg10-20020a056402548a00b004a23558f01fsm6008679edb.43.2023.02.06.23.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 23:36:11 -0800 (PST) From: Juerg Haefliger To: kernel-team@lists.ubuntu.com Subject: [Unstable/Lunar][PATCH 4/5] UBUNTU: [Packaging] annotations: Fail on invalid lines Date: Tue, 7 Feb 2023 08:36:06 +0100 Message-Id: <20230207073607.913994-5-juerg.haefliger@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230207073607.913994-1-juerg.haefliger@canonical.com> References: <20230207073607.913994-1-juerg.haefliger@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" Currently, invalid lines are silently ignored, which is not good. Fix this by raising an exception if the line can't be parsed. While at it, remove one level of nesting by using if-continue. Signed-off-by: Juerg Haefliger --- debian/scripts/misc/kconfig/annotations.py | 59 ++++++++++++---------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py index 766405c48ec1..03b01baad46b 100644 --- a/debian/scripts/misc/kconfig/annotations.py +++ b/debian/scripts/misc/kconfig/annotations.py @@ -68,33 +68,38 @@ class Annotation(Config): include_fname = dirname(abspath(self.fname)) + '/' + m.group(1) include_data = self._load(include_fname) self._parse_body(include_data) - else: - # Handle policy and note lines - if re.match(r'.* (policy|note)<', line): - try: - conf = line.split(' ')[0] - if conf in self.config: - entry = self.config[conf] - else: - entry = {'policy': {}} - - match = False - m = re.match(r'.* policy<(.*?)>', line) - if m: - match = True - entry['policy'] |= literal_eval(m.group(1)) - - m = re.match(r'.* note<(.*?)>', line) - if m: - entry['oneline'] = match - match = True - entry['note'] = "'" + m.group(1).replace("'", '') + "'" - - if not match: - raise Exception('syntax error') - self.config[conf] = entry - except Exception as e: - raise Exception(str(e) + f', line = {line}') + continue + + # Handle policy and note lines + if re.match(r'.* (policy|note)<', line): + try: + conf = line.split(' ')[0] + if conf in self.config: + entry = self.config[conf] + else: + entry = {'policy': {}} + + match = False + m = re.match(r'.* policy<(.*?)>', line) + if m: + match = True + entry['policy'] |= literal_eval(m.group(1)) + + m = re.match(r'.* note<(.*?)>', line) + if m: + entry['oneline'] = match + match = True + entry['note'] = "'" + m.group(1).replace("'", '') + "'" + + if not match: + raise Exception('syntax error') + self.config[conf] = entry + except Exception as e: + raise Exception(str(e) + f', line = {line}') + continue + + # Invalid line + raise Exception(f'invalid line: {line}') """ Parse main annotations file, individual config options can be accessed via