From patchwork Sat Sep 28 12:46:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 8156 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 (secp384r1) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "R10" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4XG6Xj1rd1z3x1M for ; Sat, 28 Sep 2024 12:46:45 +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 RSA-PSS (4096 bits) server-digest SHA256 client-signature ECDSA (secp384r1) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "E6" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4XG6Xh0Wt5z6y6; Sat, 28 Sep 2024 12:46:44 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4XG6Xg69VYz2xHl; Sat, 28 Sep 2024 12:46:43 +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 (secp384r1) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "R10" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4XG6Xd3VZ3z2xHl for ; Sat, 28 Sep 2024 12:46:41 +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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4XG6Xc3hsTz6y6; Sat, 28 Sep 2024 12:46:40 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1727527600; 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; bh=onQDIJ6pc1rmo+lYfKfZTkr0cLE8vg3XJ2hAqGPvrGo=; b=053LneLURNVA7Scw4xwyI06uD9wVuCMje0LLk6PbY0e8eaPM+c+/HKshW2yZWVxCV8MHQ6 +N2hVybL+xE0IcAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1727527600; 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; bh=onQDIJ6pc1rmo+lYfKfZTkr0cLE8vg3XJ2hAqGPvrGo=; b=oho2jaOqltD3hdN/BEpE7Ao348cKnMtdQQnu7GvUMhXoLIn2fw3AoFnUklGLD75h6YejMC oP0WlZ7dJVNmZQ3CH/NkrTvQSHZnSrofqI6QAZxw6v8OuNq4px9/P56ihQ9u8ygA/z8O99 G9neJrwCwb9PbQRNp0Uv5gnk9QzBhAYwQiAkjcYfqeybsjl5+Ud1G8mbCYO2yeBx/ldBSg HY808bf0kbAwEGVwfSyIN2/BlrSs4x5YpfpXpC312jSTxJrmIzTbFbIoLSRqWCLoUqBfdC +5/Lokcn26TMbZUpdQMGBwVYPsig5LA7TJOMY+l2W1jsKBFbP3uHF65VzsQyyQ== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH] perl: Return nothing in case invalid data has been passed to libloc Date: Sat, 28 Sep 2024 14:46:31 +0200 Message-Id: <20240928124631.39110-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: 6BQGX2V2WQAHEGH4FDSZQ2XFDCAWLB5Y X-Message-ID-Hash: 6BQGX2V2WQAHEGH4FDSZQ2XFDCAWLB5Y X-MailFrom: stefan.schantl@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "IPFire Location development/database maintainance talk." Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The old croach approch instantly will stop the script if invalid data will be passed to libloc and also will fail to proper execute the testsuite. Signed-off-by: Stefan Schantl --- src/perl/Location.xs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/perl/Location.xs b/src/perl/Location.xs index be6df14..896cbcb 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -173,7 +173,7 @@ lookup_country_code(db, address) // Lookup network int err = loc_database_lookup_from_string(db, address, &network); if (err) { - croak("Error fetching a network from the database\n"); + goto END; } // Extract the country code if we have found a network @@ -184,6 +184,8 @@ lookup_country_code(db, address) loc_network_unref(network); } + + END: OUTPUT: RETVAL @@ -213,7 +215,7 @@ lookup_network_has_flag(db, address, flag) // Lookup network int err = loc_database_lookup_from_string(db, address, &network); if (err) { - croak("Error fetching a network from the database\n"); + goto END; } // Check if the network has the given flag @@ -225,6 +227,7 @@ lookup_network_has_flag(db, address, flag) loc_network_unref(network); } + END: OUTPUT: RETVAL @@ -240,7 +243,7 @@ lookup_asn(db, address) // Lookup network int err = loc_database_lookup_from_string(db, address, &network); if (err) { - croak("Error fetching a network from the database\n"); + goto END; } // Extract the ASN @@ -252,6 +255,8 @@ lookup_asn(db, address) loc_network_unref(network); } + + END: OUTPUT: RETVAL