浏览代码

Bug 630093 - (cov#15518) Need to intialize fd in ldbm2ldif code

Currently, the ldbm_back_ldbm2ldif() function could bail due to an
error before fd is set.  We then attempt to close the file that fd
refers to.  We should initialize fd to STDOUT_FILENUM, as we skip
calling close() if fd is set to STDOUT_FILENUM.

Additionally, I noticed that we could call close() when fd is
negative or if it is STDERR or STDIN.  I fixed this so close() is
not called in those cases.
Nathan Kinder 15 年之前
父节点
当前提交
cd99e197f2
共有 1 个文件被更改,包括 3 次插入4 次删除
  1. 3 4
      ldap/servers/slapd/back-ldbm/ldif2ldbm.c

+ 3 - 4
ldap/servers/slapd/back-ldbm/ldif2ldbm.c

@@ -885,7 +885,6 @@ static IDList *ldbm_fetch_subtrees(backend *be, char **include, int *err)
     return idltotal;
 }
 
-#define FD_STDOUT 1
 
 static int
 export_one_entry(struct ldbminfo *li,
@@ -999,7 +998,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
     int              decrypt = 0;
     int              dump_replica = 0;
     int              dump_uniqueid = 1;
-    int              fd;
+    int              fd = STDOUT_FILENO;
     IDList           *idl = NULL;    /* optimization for -s include lists */
     int              cnt = 0, lastcnt = 0;
     int              options = 0;
@@ -1168,7 +1167,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
             goto bye;
         }
     } else {                    /* '-' */
-        fd = FD_STDOUT;
+        fd = STDOUT_FILENO;
     }
 
     if ( we_start_the_backends )  {
@@ -1516,7 +1515,7 @@ bye:
 
     dblayer_release_id2entry( be, db );
 
-    if (fd != FD_STDOUT) {
+    if (fd > STDERR_FILENO) {
         close(fd);
     }