From patchwork Tue Sep 27 16:48:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 6024 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4McQZ371QQz3xgM for ; Tue, 27 Sep 2022 16:48:59 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4McQZ15hJwz2Z3; Tue, 27 Sep 2022 16:48:57 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4McQZ15J4nz2yV1; Tue, 27 Sep 2022 16:48:57 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4McQYz5QX7z2yV1 for ; Tue, 27 Sep 2022 16:48:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4McQYz43kBz1qx; Tue, 27 Sep 2022 16:48:55 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1664297335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j9O558/IrEUhlWp2GzkRx0jSnKeIcEzxk8LWywC4SdQ=; b=ihsV86jJ3vlXM9TdmI6CHAdg/+tTV3tOAIH7UFVeDOzVlOyxQ5znnv/OZHxNb9WERfj8qX lEFFUBUKxgPiBjBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1664297335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j9O558/IrEUhlWp2GzkRx0jSnKeIcEzxk8LWywC4SdQ=; b=vslHWfa+Ir8XdhNw5KlgT0A8X3WEHGfTBsbnndMORO8bZBrWs5oF1rA0g4yB9CgRRsWJTy Q5QTPfsExnvF2LNAKL1Rpj3pgDtLxsj/YNuRf0xESAiEIFKOHFOIAn0lRAf293PqTypFGh vatSNRjj+5W/Q0lvy0XZWd/owI0usYMrhH5o6PzYUgraZ6qKHXzsdqS0W+IzWt6ovv1W9d BE2YsnX/F1rcl+6qR9hlrysmNvOR8c+nKGU2m1d7eoEdVJlzVobozX2A4ozkFeiq7Rn5nd 2e2iiDw7ZkhGyxpsyZl/5Xv6+ChVfpLP3ZAGZrj/3swkH8hOTQ6vOdv++URZZA== From: Michael Tremer To: location@lists.ipfire.org Subject: [PATCH 10/10] importer: Validate country codes from Geofeeds Date: Tue, 27 Sep 2022 16:48:47 +0000 Message-Id: <20220927164847.3409646-10-michael.tremer@ipfire.org> In-Reply-To: <20220927164847.3409646-1-michael.tremer@ipfire.org> References: <20220927164847.3409646-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: location-bounces@lists.ipfire.org Sender: "Location" Signed-off-by: Michael Tremer --- src/scripts/location-importer.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/scripts/location-importer.in b/src/scripts/location-importer.in index d0384b5..d8f9cbf 100644 --- a/src/scripts/location-importer.in +++ b/src/scripts/location-importer.in @@ -1421,7 +1421,15 @@ class CLI(object): log.debug("Could not parse network: %s" % network) continue - # XXX Check the country code + # Strip any excess whitespace from country codes + if country: + country = country.strip() + + # Check the country code + if not location.country_code_is_valid(country): + log.warning("Invalid country code in Geofeed %s: %s" \ + % (geofeed.url, country)) + continue # Write this into the database self.db.execute("""