chiark / gitweb /
test: udp-preload: Cope with -ve fds
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Oct 2019 19:40:06 +0000 (20:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Oct 2019 22:29:26 +0000 (23:29 +0100)
Eg, Tcl passes -1 to close (!)

 #0  0x00007f62949883ca in close (fd=-1) at udp-preload.c:207
 #1  0x00007f6294719362 in Tcl_FinalizeNotifier () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
test/udp-preload.c

index 94b399a1e7c1a0412a120b101975ff433cc7ad87..b4c0879be1836a63788122f2e7897366eb8281f4 100644 (file)
@@ -96,7 +96,7 @@ static fdinfo **table;
 static int tablesz;
 
 static fdinfo *lookup(int fd) {
-    if (fd>=tablesz) return 0;
+    if (fd<0 || fd>=tablesz) return 0;
     return table[fd];
 }
 
@@ -203,7 +203,7 @@ WRAP(socket) {
 }
 
 WRAP(close) {
-    if (fd<tablesz) {
+    if (fd>=0 && fd<tablesz) {
        free(table[fd]);
        table[fd]=0;
     }