From 93c5da169790d31212049652f62d31fd0e272596 Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 16 Jun 2022 15:30:12 +0000 Subject: [PATCH] If anything in name2id conversion fails then just return 0. Do not set any errno. So if a non empty string is used in name2id conversion and the return value is 0 then that would be an error. Callers in most cases do not care and accept that a label may be lost because of conversion failure. Noticed by and OK tb@ --- usr.sbin/bgpd/name2id.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/usr.sbin/bgpd/name2id.c b/usr.sbin/bgpd/name2id.c index 4ff16d1691b..474b068f24c 100644 --- a/usr.sbin/bgpd/name2id.c +++ b/usr.sbin/bgpd/name2id.c @@ -1,4 +1,4 @@ -/* $OpenBSD: name2id.c,v 1.11 2022/02/06 09:51:19 claudio Exp $ */ +/* $OpenBSD: name2id.c,v 1.12 2022/06/16 15:30:12 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Henning Brauer @@ -94,16 +94,18 @@ pftable_ref(uint16_t id) return (_ref(&pftable_labels, id)); } +/* + * Try to convert a name into id. If something fails 0 is returned which + * is the ID of the empty label. + */ uint16_t _name2id(struct n2id_labels *head, const char *name) { struct n2id_label *label, *p = NULL; uint16_t new_id = 1; - if (!name[0]) { - errno = EINVAL; + if (!name[0]) return (0); - } TAILQ_FOREACH(label, head, entry) if (strcmp(name, label->name) == 0) { @@ -122,10 +124,8 @@ _name2id(struct n2id_labels *head, const char *name) p->id == new_id; p = TAILQ_NEXT(p, entry)) new_id = p->id + 1; - if (new_id > IDVAL_MAX) { - errno = ERANGE; + if (new_id > IDVAL_MAX) return (0); - } if ((label = calloc(1, sizeof(struct n2id_label))) == NULL) return (0); -- 2.20.1