INN commit: trunk/tests (9 files)

INN Commit rra at isc.org
Tue Jul 31 20:23:35 UTC 2018


    Date: Tuesday, July 31, 2018 @ 13:23:35
  Author: iulius
Revision: 10295

Take into account return values of chdir and system commands

Modified:
  trunk/tests/authprogs/ident-t.c
  trunk/tests/lib/confparse-t.c
  trunk/tests/lib/innconf-t.c
  trunk/tests/lib/wire-t.c
  trunk/tests/nnrpd/auth-ext-t.c
  trunk/tests/overview/api-t.c
  trunk/tests/overview/overview-t.c
  trunk/tests/overview/xref-t.c
  trunk/tests/util/innbind-t.c

-----------------------+
 authprogs/ident-t.c   |   13 +++++++++----
 lib/confparse-t.c     |   19 +++++++++++++------
 lib/innconf-t.c       |   19 +++++++++++++------
 lib/wire-t.c          |   19 +++++++++++++------
 nnrpd/auth-ext-t.c    |   10 +++++++---
 overview/api-t.c      |   28 +++++++++++++++++++---------
 overview/overview-t.c |   25 +++++++++++++++++--------
 overview/xref-t.c     |   25 +++++++++++++++++--------
 util/innbind-t.c      |    3 ++-
 9 files changed, 110 insertions(+), 51 deletions(-)

Modified: authprogs/ident-t.c
===================================================================
--- authprogs/ident-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ authprogs/ident-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -26,7 +26,8 @@
     fd = network_connect_host(host, 11119, NULL, DEFAULT_TIMEOUT);
     if (fd < 0)
         _exit(1);
-    read(fd, buffer, sizeof(buffer));
+    if (read(fd, buffer, sizeof(buffer)) < 0)
+        sysbail("cannot read");
     close(fd);
 }
 
@@ -135,9 +136,13 @@
 int
 main(void)
 {
-    if (access("ident.t", F_OK) < 0)
-        if (access("authprogs/ident.t", F_OK) == 0)
-            chdir("authprogs");
+    if (access("ident.t", F_OK) < 0) {
+        if (access("authprogs/ident.t", F_OK) == 0) {
+            if (chdir("authprogs") < 0) {
+                sysbail("cannot chdir to authprogs");
+            }
+        }
+    }
 
     test_init(4);
     server_ipv4(1);

Modified: lib/confparse-t.c
===================================================================
--- lib/confparse-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ lib/confparse-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -362,12 +362,19 @@
 
     test_init(373);
 
-    if (access("../data/config/valid", F_OK) == 0)
-        chdir("../data");
-    else if (access("data/config/valid", F_OK) == 0)
-        chdir("data");
-    else if (access("tests/data/config/valid", F_OK) == 0)
-        chdir("tests/data");
+    if (access("../data/config/valid", F_OK) == 0) {
+        if (chdir("../data") < 0) {
+            sysbail("cannot chdir to ../data");
+        }
+    } else if (access("data/config/valid", F_OK) == 0) {
+        if (chdir("data") < 0) {
+            sysbail("cannot chdir to data");
+        }
+    } else if (access("tests/data/config/valid", F_OK) == 0) {
+        if (chdir("tests/data") < 0) {
+            sysbail("cannot chdir to tests/data");
+        }
+    }
     group = config_parse_file("config/valid");
     ok(1, group != NULL);
     if (group == NULL)

Modified: lib/innconf-t.c
===================================================================
--- lib/innconf-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ lib/innconf-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -26,12 +26,19 @@
     struct innconf *standard;
     FILE *config;
 
-    if (access("../data/config/valid", F_OK) == 0)
-        chdir("../data");
-    else if (access("data/config/valid", F_OK) == 0)
-        chdir("data");
-    else if (access("tests/data/config/valid", F_OK) == 0)
-        chdir("tests/data");
+    if (access("../data/config/valid", F_OK) == 0) {
+        if (chdir("../data") < 0) {
+            sysbail("cannot chdir to ../data");
+        }
+    } else if (access("data/config/valid", F_OK) == 0) {
+        if (chdir("data") < 0) {
+            sysbail("cannot chdir to data");
+        }
+    } else if (access("tests/data/config/valid", F_OK) == 0) {
+        if (chdir("tests/data") < 0) {
+            sysbail("cannot chdir to tests/data");
+        }
+    }
 
     test_init(9);
 

Modified: lib/wire-t.c
===================================================================
--- lib/wire-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ lib/wire-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -60,12 +60,19 @@
     ok(9, wire_findbody(p, 1) == NULL);
     ok(10, wire_findbody(p, 0) == NULL);
 
-    if (access("../data/articles/wire-strange", F_OK) == 0)
-        chdir("../data");
-    else if (access("data/articles/wire-strange", F_OK) == 0)
-        chdir("data");
-    else if (access("tests/data/articles/wire-strange", F_OK) == 0)
-        chdir("tests/data");
+    if (access("../data/articles/wire-strange", F_OK) == 0) {
+        if (chdir("../data") < 0) {
+            sysbail("cannot chdir to ../data");
+        }
+    } else if (access("data/articles/wire-strange", F_OK) == 0) {
+        if (chdir("data") < 0) {
+            sysbail("cannot chdir to data");
+        }
+    } else if (access("tests/data/articles/wire-strange", F_OK) == 0) {
+        if (chdir("tests/data") < 0) {
+            sysbail("cannot chdir to tests/data");
+        }
+    }
     article = read_file("articles/wire-strange", &st);
 
     p = wire_findbody(article, st.st_size);

Modified: nnrpd/auth-ext-t.c
===================================================================
--- nnrpd/auth-ext-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ nnrpd/auth-ext-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -108,9 +108,13 @@
     struct client *client;
     int n = 1;
 
-    if (access("auth-test", F_OK) < 0)
-        if (access("nnrpd/auth-test", F_OK) == 0)
-            chdir("nnrpd");
+    if (access("auth-test", F_OK) < 0) {
+        if (access("nnrpd/auth-test", F_OK) == 0) {
+            if (chdir("nnrpd") < 0) {
+                sysbail("cannot chdir to nnrpd");
+            }
+        }
+    }
     client = client_new();
 
     test_init(11 * 6);

Modified: overview/api-t.c
===================================================================
--- overview/api-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ overview/api-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -109,7 +109,8 @@
 static struct overview *
 overview_init(void)
 {
-    system("/bin/rm -rf ov-tmp");
+    if (system("/bin/rm -rf ov-tmp") < 0)
+        sysdie("Cannot rm ov-tmp");
     if (mkdir("ov-tmp", 0755))
         sysdie("Cannot mkdir ov-tmp");
     if (strcmp(innconf->ovmethod, "buffindexed") == 0)
@@ -583,7 +584,8 @@
     ok(n++, overview_verify_data("overview/bogus", overview));
     hash_free(groups);
     overview_close(overview);
-    system("/bin/rm -rf ov-tmp");
+    if (system("/bin/rm -rf ov-tmp") < 0)
+        sysdie("Cannot rm ov-tmp");
     ok(n++, true);
     return n;
 }
@@ -679,7 +681,8 @@
     ok(n++, overview_verify_data("overview/bogus", overview));
     hash_free(groups);
     overview_close(overview);
-    system("/bin/rm -rf ov-tmp");
+    if (system("/bin/rm -rf ov-tmp") < 0)
+        sysdie("Cannot rm ov-tmp");
     ok(n++, true);
     return n;
 }
@@ -689,12 +692,19 @@
 {
     int n = 1;
 
-    if (access("../data/overview/basic", F_OK) == 0)
-        chdir("../data");
-    else if (access("data/overview/basic", F_OK) == 0)
-        chdir("data");
-    else if (access("tests/data/overview/basic", F_OK) == 0)
-        chdir("tests/data");
+    if (access("../data/overview/basic", F_OK) == 0) {
+        if (chdir("../data") < 0) {
+            sysbail("cannot chdir to ../data");
+        }
+    } else if (access("data/overview/basic", F_OK) == 0) {
+        if (chdir("data") < 0) {
+            sysbail("cannot chdir to data");
+        }
+    } else if (access("tests/data/overview/basic", F_OK) == 0) {
+        if (chdir("tests/data") < 0) {
+            sysbail("cannot chdir to tests/data");
+        }
+    }
 
     /* Cancels can't be tested with mmap, so there are only 21 tests there. */
     test_init(27 * 2 + 21);

Modified: overview/overview-t.c
===================================================================
--- overview/overview-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ overview/overview-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -123,7 +123,8 @@
 static bool
 overview_init(void)
 {
-    system("/bin/rm -rf ov-tmp");
+    if (system("/bin/rm -rf ov-tmp") < 0)
+        sysdie("Cannot rm ov-tmp");
     if (mkdir("ov-tmp", 0755))
         sysdie("Cannot mkdir ov-tmp");
     if (strcmp(innconf->ovmethod, "buffindexed") == 0)
@@ -503,12 +504,19 @@
 
     test_init(21);
 
-    if (access("../data/overview/basic", F_OK) == 0)
-        chdir("../data");
-    else if (access("data/overview/basic", F_OK) == 0)
-        chdir("data");
-    else if (access("tests/data/overview/basic", F_OK) == 0)
-        chdir("tests/data");
+    if (access("../data/overview/basic", F_OK) == 0) {
+        if (chdir("../data") < 0) {
+            sysbail("cannot chdir to ../data");
+        }
+    } else if (access("data/overview/basic", F_OK) == 0) {
+        if (chdir("data") < 0) {
+            sysbail("cannot chdir to data");
+        }
+    } else if (access("tests/data/overview/basic", F_OK) == 0) {
+        if (chdir("tests/data") < 0) {
+            sysbail("cannot chdir to tests/data");
+        }
+    }
 
     fake_innconf();
     if (!overview_init())
@@ -562,7 +570,8 @@
     ok(20, overview_verify_data("overview/bogus"));
     hash_free(groups);
     OVclose();
-    system("/bin/rm -rf ov-tmp");
+    if (system("/bin/rm -rf ov-tmp") <0)
+        sysdie("Cannot rm ov-tmp");
     ok(21, true);
 
     return 0;

Modified: overview/xref-t.c
===================================================================
--- overview/xref-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ overview/xref-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -49,7 +49,8 @@
 static struct overview *
 overview_init(void)
 {
-    system("/bin/rm -rf ov-tmp spool");
+    if (system("/bin/rm -rf ov-tmp spool") < 0)
+        sysdie("Cannot rm ov-tmp spool");
     if (mkdir("ov-tmp", 0755))
         sysdie("Cannot mkdir ov-tmp");
     if (mkdir("spool", 0755))
@@ -188,12 +189,19 @@
     ARTHANDLE handle = ARTHANDLE_INITIALIZER;
     TOKEN token;
 
-    if (access("../data/overview/xref", F_OK) == 0)
-        chdir("../data");
-    else if (access("data/overview/xref", F_OK) == 0)
-        chdir("data");
-    else if (access("tests/data/overview/xref", F_OK) == 0)
-        chdir("tests/data");
+    if (access("../data/overview/xref", F_OK) == 0) {
+        if (chdir("../data") < 0) {
+            sysbail("cannot chdir to ../data");
+        }
+    } else if (access("data/overview/xref", F_OK) == 0) {
+        if (chdir("data") < 0) {
+            sysbail("cannot chdir to data");
+        }
+    } else if (access("tests/data/overview/xref", F_OK) == 0) {
+        if (chdir("tests/data") < 0) {
+            sysbail("cannot chdir to tests/data");
+        }
+    }
 
     /* 7 group/article pairs plus one check for each insert plus the final
        check for the count. */
@@ -244,6 +252,7 @@
     ok(n++, !overview_token(overview, "example.test3", 2, &token));
     ok(n++, overview_token(overview, "example.test3", 3, &token));
 
-    system("/bin/rm -rf ov-tmp spool");
+    if (system("/bin/rm -rf ov-tmp spool") < 0)
+        sysdie("Cannot rm ov-tmp spool");
     return 0;
 }

Modified: util/innbind-t.c
===================================================================
--- util/innbind-t.c	2018-06-25 20:41:46 UTC (rev 10294)
+++ util/innbind-t.c	2018-07-31 20:23:35 UTC (rev 10295)
@@ -317,7 +317,8 @@
 
     if (access("innbind.t", F_OK) < 0)
         if (access("util/innbind.t", F_OK) == 0)
-            chdir("util");
+            if (chdir("util") < 0)
+                sysbail("cannot chdir to util");
 
     test_init(15);
 



More information about the inn-committers mailing list