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.
This commit is contained in:
Todd C. Miller
2011-05-25 12:54:15 -04:00
parent 682333ae2d
commit 2b98492871

View File

@@ -44,6 +44,7 @@
#include "parse.h" #include "parse.h"
#include "redblack.h" #include "redblack.h"
#include <gram.h> #include <gram.h>
#include <errno.h>
/* /*
* Globals * Globals
@@ -91,9 +92,13 @@ alias_find(char *name, int type)
* before and found a loop. * before and found a loop.
*/ */
a = node->data; a = node->data;
if (a->seqno == alias_seqno) if (a->seqno == alias_seqno) {
errno = ELOOP;
return NULL; return NULL;
}
a->seqno = alias_seqno; a->seqno = alias_seqno;
} else {
errno = ENOENT;
} }
return a; return a;
} }
@@ -175,8 +180,10 @@ alias_remove(char *name, int type)
key.name = name; key.name = name;
key.type = type; key.type = type;
if ((node = rbfind(aliases, &key)) == NULL) if ((node = rbfind(aliases, &key)) == NULL) {
errno = ENOENT;
return NULL; return NULL;
}
return rbdelete(aliases, node); return rbdelete(aliases, node);
} }