Changeset: 7c5eac016540 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7c5eac016540
Modified Files:
        gdk/gdk_bbp.c
        gdk/gdk_heap.c
Branch: Jan2014
Log Message:

Fix some time-of-check time-of-use problems.


diffs (49 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3650,11 +3650,6 @@ BBPdiskscan(const char *parent)
                        /* it was a directory */
                        continue;
                }
-               if (stat(fullname, &st)) {
-                       IODEBUG mnstr_printf(GDKstdout,"BBPdiskscan: stat(%s)", 
fullname);
-                       continue;
-               }
-               IODEBUG THRprintf(GDKstdout, "#BBPdiskscan: stat(%s) = 0\n", 
fullname);
 
                if (ok == FALSE || !persistent_bat(bid)) {
                        delete = TRUE;
@@ -3688,7 +3683,7 @@ BBPdiskscan(const char *parent)
                        break;
                }
                if (delete) {
-                       if (unlink(fullname) < 0) {
+                       if (unlink(fullname) < 0 && errno != ENOENT) {
                                GDKsyserror("BBPdiskscan: unlink(%s)", 
fullname);
                                continue;
                        }
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -651,15 +651,15 @@ HEAPload_intern(Heap *h, const char *nme
        GDKfilepath(dstpath, BATDIR, nme, ext);
        assert(strlen(srcpath) + strlen(suffix) < sizeof(srcpath));
        strcat(srcpath, suffix);
-       ret = stat(dstpath, &st);
        if (stat(srcpath, &st) == 0) {
                int t0;
-               if (ret == 0) {
-                       t0 = GDKms();
-                       ret = unlink(dstpath);
-                       HEAPDEBUG fprintf(stderr, "#unlink %s = %d (%dms)\n", 
dstpath, ret, GDKms() - t0);
-               }
                t0 = GDKms();
+               ret = unlink(dstpath);
+               if (ret < 0 && errno == ENOENT)
+                       ret = 0; /* no error if it doesn't exist */
+               HEAPDEBUG fprintf(stderr, "#unlink %s = %d (%dms)\n", dstpath, 
ret, GDKms() - t0);
+               t0 = GDKms();
+               /* coverity[toctou] */
                ret = rename(srcpath, dstpath);
                if (ret < 0) {
                        GDKsyserror("HEAPload: rename of %s failed\n", srcpath);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to