]> granicus.if.org Git - shadow/commitdiff
Do not crash in commonio_close if database FILE not opened.
authorTomas Mraz <tmraz@fedoraproject.org>
Mon, 25 Mar 2019 13:51:26 +0000 (14:51 +0100)
committerTomas Mraz <tmraz@fedoraproject.org>
Mon, 25 Mar 2019 13:51:26 +0000 (14:51 +0100)
The db->fp can be NULL if commonio_unlock() is called when the
shadow file is opened but did not exist before.

lib/commonio.c

index 0b9022ef7d6f7ebe70cfb5b459dbe3afc41f3308..26e518f2297ab29ebaec4f5fedd097af31dcf627 100644 (file)
@@ -925,7 +925,6 @@ static int write_all (const struct commonio_db *db)
 
 
 int commonio_close (struct commonio_db *db)
-       /*@requires notnull db->fp@*/
 {
        char buf[1024];
        int errors = 0;
@@ -938,8 +937,10 @@ int commonio_close (struct commonio_db *db)
        db->isopen = false;
 
        if (!db->changed || db->readonly) {
-               (void) fclose (db->fp);
-               db->fp = NULL;
+               if (NULL != db->fp) {
+                       (void) fclose (db->fp);
+                       db->fp = NULL;
+               }
                goto success;
        }