]> granicus.if.org Git - sudo/commitdiff
Set errno to ELOOP in alias_find() if there is a cycle. Set errno
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 13 Aug 2011 18:40:17 +0000 (14:40 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 13 Aug 2011 18:40:17 +0000 (14:40 -0400)
to ENOENT in alias_find() and alias_remove() if the entry could not
be found.

--HG--
branch : 1.7

alias.c

diff --git a/alias.c b/alias.c
index 238830c7bbd948d72a6d953d45cf09d9244df64c..96b883b771238e5d625639344256438e8a098692 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -44,6 +44,7 @@
 #include "parse.h"
 #include "redblack.h"
 #include <gram.h>
+#include <errno.h>
 
 /*
  * 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);
 }