From b92c8615ab695342b1cd64b1574ba83009c10477 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 13 Aug 2011 14:40:17 -0400 Subject: [PATCH] Set errno to ELOOP in alias_find() if there is a cycle. Set errno to ENOENT in alias_find() and alias_remove() if the entry could not be found. --HG-- branch : 1.7 --- alias.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/alias.c b/alias.c index 238830c7b..96b883b77 100644 --- a/alias.c +++ b/alias.c @@ -44,6 +44,7 @@ #include "parse.h" #include "redblack.h" #include +#include /* * Globals @@ -88,15 +89,19 @@ alias_find(name, type) key.name = name; key.type = type; if ((node = rbfind(aliases, &key)) != NULL) { - /* - * Compare the global sequence number with the one stored - * in the alias. If they match then we've seen this alias - * before and found a loop. - */ - a = node->data; - if (a->seqno == alias_seqno) - return NULL; - a->seqno = alias_seqno; + /* + * Compare the global sequence number with the one stored + * in the alias. If they match then we've seen this alias + * before and found a loop. + */ + a = node->data; + if (a->seqno == alias_seqno) { + errno = ELOOP; + return NULL; + } + a->seqno = alias_seqno; + } else { + errno = ENOENT; } return a; } @@ -186,8 +191,10 @@ alias_remove(name, type) key.name = name; key.type = type; - if ((node = rbfind(aliases, &key)) == NULL) + if ((node = rbfind(aliases, &key)) == NULL) { + errno = ENOENT; return NULL; + } return rbdelete(aliases, node); } -- 2.40.0