From cd99e197f22f7a26fae930d72b507a92e06313a8 Mon Sep 17 00:00:00 2001 From: Nathan Kinder Date: Wed, 8 Sep 2010 09:51:21 -0700 Subject: 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. --- ldap/servers/slapd/back-ldbm/ldif2ldbm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c index 1b7b7ae4..f1b50ae3 100644 --- a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c +++ b/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); } -- cgit