When an invalid country code is entered, loc_country_new returns an
error which is interpreted as a match to the list since we check for a
non-zero return code.
Any invalid country codes are now silently ignored and not considered a
match.
Fixes: #12620 - "location list-networks-by-cc" returns garbage
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
struct loc_country* country;
int r = loc_country_new(list->ctx, &country, code);
- if (r)
- return -1;
+ if (r) {
+ // Ignore invalid country codes which would never match
+ if (errno == EINVAL)
+ return 0;
+ else
+ return r;
+ }
r = loc_country_list_contains(list, country);
loc_country_unref(country);
};
LOC_EXPORT int loc_country_new(struct loc_ctx* ctx, struct loc_country** country, const char* country_code) {
- if (!loc_country_code_is_valid(country_code))
- return -EINVAL;
+ // Check of the country code is valid
+ if (!loc_country_code_is_valid(country_code)) {
+ errno = EINVAL;
+ return 1;
+ }
struct loc_country* c = calloc(1, sizeof(*c));
if (!c)