diff options
author | Noriko Hosoi <nhosoi@redhat.com> | 2010-08-20 17:12:52 -0700 |
---|---|---|
committer | Noriko Hosoi <nhosoi@redhat.com> | 2010-08-23 11:05:28 -0700 |
commit | 936c24aba64eac82ef7054d09d7b9bd8b01a5aca (patch) | |
tree | 4a5ed69184c344124a32c964071c559d654ef287 | |
parent | fdd0c5f453fe368f2a8732bb0ae16bd68d6b5b13 (diff) | |
download | ds-936c24aba64eac82ef7054d09d7b9bd8b01a5aca.tar.gz ds-936c24aba64eac82ef7054d09d7b9bd8b01a5aca.tar.xz ds-936c24aba64eac82ef7054d09d7b9bd8b01a5aca.zip |
Bug 610119 - fix coverify Defect Type: Null pointer dereferences issues 12167 - 12199
https://bugzilla.redhat.com/show_bug.cgi?id=610119
Resolves: bug 610119
Bug description: Fix coverify Defect Type: Null pointer dereferences issues 12167 - 12199
Fix description: Catch possible NULL pointer in ldbm_back_ldbm2ldif(),
ldbm_back_upgradedb(), upgradedb_copy_logfiles().
coverity ID: 12190
-rw-r--r-- | ldap/servers/slapd/back-ldbm/dblayer.c | 2 | ||||
-rw-r--r-- | ldap/servers/slapd/back-ldbm/ldif2ldbm.c | 38 |
2 files changed, 24 insertions, 16 deletions
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c index 41f7c266..5a7079ef 100644 --- a/ldap/servers/slapd/back-ldbm/dblayer.c +++ b/ldap/servers/slapd/back-ldbm/dblayer.c @@ -4740,6 +4740,8 @@ dblayer_copyfile(char *source, char *destination, int overwrite, int mode) destination); goto error; } + LDAPDebug2Args(LDAP_DEBUG_BACKLDBM, + "Copying %s to %s\n", source, destination); /* Loop round reading data and writing it */ while (1) { diff --git a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c index ea493ee6..b9fec3e8 100644 --- a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c +++ b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c @@ -1212,7 +1212,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb ) */ /* get a cursor to we can walk over the table */ return_value = db->cursor(db,NULL,&dbc,0); - if (0 != return_value ) { + if (0 != return_value || NULL == dbc) { LDAPDebug2Args(LDAP_DEBUG_ANY, "Failed to get cursor for db2ldif; %s (%d)\n", dblayer_strerror(return_value), return_value); @@ -1506,7 +1506,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb ) "export %s: Processed %d entries (100%%).\n", inst->inst_name, cnt, 0); } - +bye: if (idl) { idl_free(idl); } @@ -1522,24 +1522,22 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb ) LDAPDebug( LDAP_DEBUG_TRACE, "<= ldbm_back_ldbm2ldif\n", 0, 0, 0 ); - if (we_start_the_backends && 0 != dblayer_flush(li)) { - LDAPDebug( LDAP_DEBUG_ANY, "db2ldif: Failed to flush database\n", - 0, 0, 0 ); - } + if (we_start_the_backends && NULL != li) { + if (0 != dblayer_flush(li)) { + LDAPDebug0Args( LDAP_DEBUG_ANY, + "db2ldif: Failed to flush database\n" ); + } - if (we_start_the_backends) { if (0 != dblayer_close(li,DBLAYER_EXPORT_MODE)) { - LDAPDebug( LDAP_DEBUG_ANY, - "db2ldif: Failed to close database\n", - 0, 0, 0 ); + LDAPDebug0Args( LDAP_DEBUG_ANY, + "db2ldif: Failed to close database\n" ); } } - if (!run_from_cmdline) { + if (!run_from_cmdline && NULL != inst) { instance_set_not_busy(inst); } -bye: ldbm_back_free_incl_excl(include_suffix, exclude_suffix); idl_free(eargs.pre_exported_idl); if (inst != NULL) { @@ -2848,6 +2846,16 @@ int upgradedb_copy_logfiles(struct ldbminfo *li, char *destination_dir, src = li->li_directory; dest = destination_dir; } + if (NULL == src || '\0' == *src) { + LDAPDebug0Args(LDAP_DEBUG_ANY, "upgradedb_copy_logfiles: " + "NULL src directory\n"); + return -1; + } + if (NULL == dest || '\0' == *dest) { + LDAPDebug0Args(LDAP_DEBUG_ANY, "upgradedb_copy_logfiles: " + "NULL dest directory\n"); + return -1; + } srclen = strlen(src); destlen = strlen(dest); @@ -2888,7 +2896,7 @@ int upgradedb_copy_logfiles(struct ldbminfo *li, char *destination_dir, from = slapi_ch_calloc(1, fromlen); len0 = fromlen; } - sprintf(from, "%s/%s", src, direntry->name); + PR_snprintf(from, len0, "%s/%s", src, direntry->name); tolen = destlen + filelen + 2; if (len1 < tolen) { @@ -2896,9 +2904,7 @@ int upgradedb_copy_logfiles(struct ldbminfo *li, char *destination_dir, to = slapi_ch_calloc(1, tolen); len1 = tolen; } - sprintf(to, "%s/%s", dest, direntry->name); - if (NULL == from || NULL == to) - break; + PR_snprintf(to, len1, "%s/%s", dest, direntry->name); rval = dblayer_copyfile(from, to, 1, DEFAULT_MODE); if (rval < 0) break; |