perl: Return nothing in case invalid data has been passed to libloc

Message ID 20240928124631.39110-1-stefan.schantl@ipfire.org
State New
Headers
Series perl: Return nothing in case invalid data has been passed to libloc |

Commit Message

Stefan Schantl Sept. 28, 2024, 12:46 p.m. UTC
  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 <stefan.schantl@ipfire.org>
---
 src/perl/Location.xs | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
  

Patch

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