diff options
Diffstat (limited to 'ldap')
55 files changed, 301 insertions, 1276 deletions
diff --git a/ldap/admin/include/dsalib.h b/ldap/admin/include/dsalib.h index e7f1378e..b2fb483f 100644 --- a/ldap/admin/include/dsalib.h +++ b/ldap/admin/include/dsalib.h @@ -329,10 +329,6 @@ extern DS_EXPORT_SYMBOL char* dn_normalize_convert (char* DN); /* if dn contains an unescaped quote return true */ extern DS_EXPORT_SYMBOL int ds_dn_uses_LDAPv2_quoting(const char *dn); -/* Return != 0 iff the DN equals or ends with the given suffix. - Both DN and suffix must be normalized, by dn_normalize(). */ -extern DS_EXPORT_SYMBOL int dn_issuffix (char* DN, char* suffix); - /* Return a copy of the DN, but with optional whitespace inserted. */ extern DS_EXPORT_SYMBOL char* ds_dn_expand (char* DN); diff --git a/ldap/admin/lib/dsalib_debug.c b/ldap/admin/lib/dsalib_debug.c index 797b84dc..5c777845 100644 --- a/ldap/admin/lib/dsalib_debug.c +++ b/ldap/admin/lib/dsalib_debug.c @@ -11,6 +11,7 @@ #include <string.h> #include <stdlib.h> #include "nspr.h" +#include "plstr.h" #if defined( XP_WIN32 ) int ldap_debug = 0; @@ -23,8 +24,7 @@ ds_log_env(char **envp) char admin_logfile[PATH_MAX], *tmp_dir; tmp_dir = ds_get_tmp_dir(); - memset( admin_logfile, 0, sizeof( admin_logfile ) ); - strcat( admin_logfile, tmp_dir ); + PL_strncpyz( admin_logfile, tmp_dir, sizeof(admin_logfile) ); #if defined( XP_WIN32 ) if( tmp_dir ) { @@ -32,7 +32,7 @@ ds_log_env(char **envp) tmp_dir = NULL; } #endif - strcat( admin_logfile, "/admin.log"); + PL_strcatn( admin_logfile, sizeof(admin_logfile), "/admin.log"); file = fopen(admin_logfile, "a+"); if (file != NULL) { @@ -55,7 +55,7 @@ ds_log_debug_message(char *msg) tmp_dir = ds_get_tmp_dir(); memset( admin_logfile, 0, sizeof( admin_logfile ) ); - strcat( admin_logfile, tmp_dir ); + PL_strncpyz( admin_logfile, tmp_dir, sizeof(admin_logfile) ); #if defined( XP_WIN32 ) if( tmp_dir ) { @@ -63,7 +63,7 @@ ds_log_debug_message(char *msg) tmp_dir = NULL; } #endif - strcat( admin_logfile, "/admin.log"); + PL_strcatn( admin_logfile, sizeof(admin_logfile), "/admin.log"); file = fopen(admin_logfile, "a+"); if (file != NULL) { diff --git a/ldap/admin/lib/dsalib_dn.c b/ldap/admin/lib/dsalib_dn.c index 89f03f1f..381f04e8 100644 --- a/ldap/admin/lib/dsalib_dn.c +++ b/ldap/admin/lib/dsalib_dn.c @@ -126,28 +126,6 @@ dn_normalize( char *dn ) return( dn ); } -DS_EXPORT_SYMBOL int -dn_issuffix( - char *dn, - char *suffix -) -{ - int dnlen, suffixlen; - - if ( dn == NULL ) { - return( 0 ); - } - - suffixlen = strlen( suffix ); - dnlen = strlen( dn ); - - if ( suffixlen > dnlen ) { - return( 0 ); - } - - return( strcasecmp( dn + dnlen - suffixlen, suffix ) == 0 ); -} - DS_EXPORT_SYMBOL char* ds_dn_expand (char* dn) { @@ -159,6 +137,7 @@ ds_dn_expand (char* dn) if (dn == NULL) return NULL; edn = strdup (dn); + if (edn == NULL) return NULL; for (s = dn; *s != '\0'; ++s, ++i) { switch (state) { case B4TYPE: diff --git a/ldap/admin/lib/dsalib_filename.c b/ldap/admin/lib/dsalib_filename.c index 6007176c..117b8952 100644 --- a/ldap/admin/lib/dsalib_filename.c +++ b/ldap/admin/lib/dsalib_filename.c @@ -55,10 +55,9 @@ ds_get_file_meaning(char *file) if ( file == NULL ) return(NULL); - name = malloc(strlen(file) + 1); + name = strdup(file); if ( name == NULL ) return(NULL); - strcpy(name, file); if ( (tmp = strrchr(name, '.')) != NULL ) *tmp = '\0'; if ( strlen(name) == FILE_EXPECTED_SIZE1 ) { diff --git a/ldap/admin/lib/dsalib_ldif.c b/ldap/admin/lib/dsalib_ldif.c index 3a126ce8..40c0ae8c 100644 --- a/ldap/admin/lib/dsalib_ldif.c +++ b/ldap/admin/lib/dsalib_ldif.c @@ -20,6 +20,7 @@ #include <string.h> #include <errno.h> #include "nspr.h" +#include "plstr.h" #ifndef XP_WIN32 #define SCRIPT_SUFFIX "" /* shell scripts have no suffix */ @@ -303,7 +304,7 @@ ds_db2ldif_subtree(char *file, char *subtree) if ( file == NULL ) *outfile = 0; else - strcpy( outfile, file ); + PL_strncpyz( outfile, file, sizeof(outfile) ); PR_snprintf(scriptfile, PATH_MAX, "%s%cdb2ldif", root, FILE_SEP); diff --git a/ldap/admin/lib/dsalib_location.c b/ldap/admin/lib/dsalib_location.c index 600cc19c..d5057349 100644 --- a/ldap/admin/lib/dsalib_location.c +++ b/ldap/admin/lib/dsalib_location.c @@ -11,6 +11,7 @@ #include <string.h> #include <stdlib.h> #include "nspr.h" +#include "plstr.h" /* * Returns the server root. Info is @@ -118,7 +119,7 @@ ds_get_logfile_name(int config_type) free(filename); return(NULL); } - strncpy(logfile, filename, PATH_MAX); + PL_strncpyz(logfile, filename, sizeof(logfile)); free(filename); return(logfile); } diff --git a/ldap/admin/lib/dsalib_tailf.c b/ldap/admin/lib/dsalib_tailf.c index db539479..62143db4 100644 --- a/ldap/admin/lib/dsalib_tailf.c +++ b/ldap/admin/lib/dsalib_tailf.c @@ -13,6 +13,7 @@ #include <sys/stat.h> #include "dsalib.h" #include "prthread.h" +#include "plstr.h" /* * Function: adjustFile @@ -166,7 +167,7 @@ ds_display_tail(char *fileName, int timeOut, int startSeek, char *doneMsg, { char *tmp; if (lastLine != NULL) - strcpy(lastLine, msgBuf); + PL_strncpyz(lastLine, msgBuf, BIG_LINE); if ( (tmp = strchr(msgBuf, ((int) '\n'))) != NULL ) *tmp = '\0'; /* strip out real newlines from here */ ds_send_status(msgBuf); diff --git a/ldap/admin/lib/dsalib_util.c b/ldap/admin/lib/dsalib_util.c index 1f8335fa..c17d3747 100644 --- a/ldap/admin/lib/dsalib_util.c +++ b/ldap/admin/lib/dsalib_util.c @@ -290,9 +290,11 @@ ds_get_tmp_dir() if(instanceDir == NULL) { #if defined( XP_WIN32 ) - ilen = strlen(tmp); - GetTempPath( ilen +1, tmp ); + ilen = sizeof(tmp); + GetTempPath( ilen, tmp ); + tmp[ilen-1] = (char)0; /* Remove trailing slash. */ + ilen = strlen(tmp); pch = tmp[ilen-1]; if( pch == '\\' || pch == '/' ) tmp[ilen-1] = '\0'; @@ -642,7 +644,7 @@ alter_startup_line(char *startup_line) char temp_startup_line[BIG_LINE+40]; PR_snprintf(temp_startup_line, sizeof(temp_startup_line), "/bin/sh -c \"%s\"", startup_line); - strcpy(startup_line, temp_startup_line); + PL_strncpyz(startup_line, temp_startup_line, BIG_LINE); #else /* do nothing */ #endif /* Linux */ diff --git a/ldap/admin/src/addindex.c b/ldap/admin/src/addindex.c index 608bef6f..84b0bdbf 100644 --- a/ldap/admin/src/addindex.c +++ b/ldap/admin/src/addindex.c @@ -51,6 +51,11 @@ int main(int argc, char *argv[]) attrs = strdup( attributes ); + if (attrs == NULL) { + rpt_err(DS_MEMORY_ERROR, "Out of memory!", NULL, NULL); + return 1; + } + /* Allocate for worst possible case */ attrList = (char **)malloc(sizeof(*attrList) * (strlen(attrs)+1)); nAttrs = 0; diff --git a/ldap/admin/src/create_instance.c b/ldap/admin/src/create_instance.c index d2a332ac..cd81741f 100644 --- a/ldap/admin/src/create_instance.c +++ b/ldap/admin/src/create_instance.c @@ -440,21 +440,21 @@ static char *sanity_check(server_config_s *cf, char *param_name) { if( (t = create_instance_checkport(cf->bindaddr, cf->servport)) ) { - strcpy(param_name, "servport"); + PL_strncpyz(param_name, "servport", BIG_LINE); return t; } if ( cf->secserv && (strcmp(cf->secserv, "on") == 0) && (cf->secservport != NULL) && (*(cf->secservport) != '\0') ) { if ( (t = create_instance_checkport(cf->bindaddr, cf->secservport)) ) { - strcpy(param_name, "secservport"); + PL_strncpyz(param_name, "secservport", BIG_LINE); return t; } } if ( cf->ntsynch && (strcmp(cf->ntsynch, "on") == 0) && (cf->ntsynchport != NULL) && (*(cf->ntsynchport) != '\0') ) { if ( (t = create_instance_checkport(cf->bindaddr, cf->ntsynchport)) ) { - strcpy(param_name, "ntsynchport"); + PL_strncpyz(param_name, "ntsynchport", BIG_LINE); return t; } } @@ -463,7 +463,7 @@ static char *sanity_check(server_config_s *cf, char *param_name) /* is the server identifier good? */ for(x=0; cf->servid[x]; x++) { if(strchr("/ &;`'\"|*!?~<>^()[]{}$\\", cf->servid[x])) { - strcpy(param_name, "servid"); + PL_strncpyz(param_name, "servid", BIG_LINE); return make_error("You used a shell-specific character in " "your server id (the character was %c).", cf->servid[x]); @@ -476,7 +476,7 @@ static char *sanity_check(server_config_s *cf, char *param_name) /* Not an error to upgrade! ??? if ( !cf->upgradingServer ) { if(create_instance_exists(fn)) { - strcpy(param_name, "servid"); + PL_strncpyz(param_name, "servid", BIG_LINE); return make_error ("A server named '%s' already exists." "\nPlease choose another server identifier.", cf->servid); @@ -487,7 +487,7 @@ static char *sanity_check(server_config_s *cf, char *param_name) #ifdef XP_UNIX if( (t = create_instance_checkuser(cf->servuser)) ) { - strcpy(param_name, "servuser"); + PL_strncpyz(param_name, "servuser", BIG_LINE); return t; } #endif @@ -496,53 +496,53 @@ static char *sanity_check(server_config_s *cf, char *param_name) #ifdef XP_UNIX if((!create_instance_numbers(cf->numprocs)) || (atoi(cf->numprocs) <= 0)) { - strcpy(param_name, "numprocs"); + PL_strncpyz(param_name, "numprocs", BIG_LINE); return ("The number of processes must be not be zero or " "negative."); } #endif if((!create_instance_numbers(cf->maxthreads)) || (atoi(cf->maxthreads) <= 0)) { - strcpy(param_name, "maxthreads"); + PL_strncpyz(param_name, "maxthreads", BIG_LINE); return ("The maximum threads must be not be zero or negative."); } if((!create_instance_numbers(cf->minthreads)) || (atoi(cf->minthreads) <= 0)) { - strcpy(param_name, "minthreads"); + PL_strncpyz(param_name, "minthreads", BIG_LINE); return ("The minumum threads must be not be zero or negative."); } if((atoi(cf->minthreads)) > (atoi(cf->maxthreads))) { - strcpy(param_name, "minthreads"); + PL_strncpyz(param_name, "minthreads", BIG_LINE); return ("Minimum threads must be less than maximum threads."); } /* see if the DN parameters are valid DNs */ if (!cf->use_existing_user_ds && (t = isAValidDN(cf->suffix))) { - strcpy(param_name, "suffix"); + PL_strncpyz(param_name, "suffix", BIG_LINE); return t; } checkForLDAPv2Quoting(cf->suffix); if (NULL != (t = isAValidDN(cf->rootdn))) { - strcpy(param_name, "rootdn"); + PL_strncpyz(param_name, "rootdn", BIG_LINE); return t; } checkForLDAPv2Quoting(cf->rootdn); if (cf->replicationdn && *cf->replicationdn && (t = isAValidDN(cf->replicationdn))) { - strcpy(param_name, "replicationdn"); + PL_strncpyz(param_name, "replicationdn", BIG_LINE); return t; } checkForLDAPv2Quoting(cf->replicationdn); if (cf->consumerdn && *cf->consumerdn && (t = isAValidDN(cf->consumerdn))) { - strcpy(param_name, "consumerdn"); + PL_strncpyz(param_name, "consumerdn", BIG_LINE); return t; } checkForLDAPv2Quoting(cf->consumerdn); @@ -550,7 +550,7 @@ static char *sanity_check(server_config_s *cf, char *param_name) if (cf->changelogsuffix && *cf->changelogsuffix && (t = isAValidDN(cf->changelogsuffix))) { - strcpy(param_name, "changelogsuffix"); + PL_strncpyz(param_name, "changelogsuffix", BIG_LINE); return t; } checkForLDAPv2Quoting(cf->changelogsuffix); @@ -558,7 +558,7 @@ static char *sanity_check(server_config_s *cf, char *param_name) if (cf->netscaperoot && *cf->netscaperoot && (t = isAValidDN(cf->netscaperoot))) { - strcpy(param_name, "netscaperoot"); + PL_strncpyz(param_name, "netscaperoot", BIG_LINE); return t; } checkForLDAPv2Quoting(cf->netscaperoot); @@ -566,32 +566,32 @@ static char *sanity_check(server_config_s *cf, char *param_name) if (cf->samplesuffix && *cf->samplesuffix && (t = isAValidDN(cf->samplesuffix))) { - strcpy(param_name, "samplesuffix"); + PL_strncpyz(param_name, "samplesuffix", BIG_LINE); return t; } checkForLDAPv2Quoting(cf->samplesuffix); if (NULL != (t = contains8BitChars(cf->rootpw))) { - strcpy(param_name, "rootpw"); + PL_strncpyz(param_name, "rootpw", BIG_LINE); return t; } if (NULL != (t = contains8BitChars(cf->cfg_sspt_uidpw))) { - strcpy(param_name, "cfg_sspt_uidpw"); + PL_strncpyz(param_name, "cfg_sspt_uidpw", BIG_LINE); return t; } if (NULL != (t = contains8BitChars(cf->replicationpw))) { - strcpy(param_name, "replicationpw"); + PL_strncpyz(param_name, "replicationpw", BIG_LINE); return t; } if (NULL != (t = contains8BitChars(cf->consumerpw))) { - strcpy(param_name, "consumerpw"); + PL_strncpyz(param_name, "consumerpw", BIG_LINE); return t; } @@ -605,7 +605,7 @@ static char *sanity_check(server_config_s *cf, char *param_name) { if (NULL != (t = contains8BitChars(cf->cfg_sspt_uid))) { - strcpy(param_name, "cfg_sspt_uid"); + PL_strncpyz(param_name, "cfg_sspt_uid", BIG_LINE); return t; } } @@ -1107,7 +1107,7 @@ char *create_server(server_config_s *cf, char *param_name) #else /* Abort if the service exists on NT */ if (t = service_exists(cf->servid)) { - strcpy(param_name, "servid"); + PL_strncpyz(param_name, "servid", BIG_LINE); return t; } #endif @@ -4397,7 +4397,7 @@ static char *install_ds(char *sroot, server_config_s *cf, char *param_name) /* find the server's UID and GID */ if (cf->servuser && *(cf->servuser)) { if ((pw = getpwnam (cf->servuser)) == NULL) { - strcpy(param_name, "servuser"); + PL_strncpyz(param_name, "servuser", BIG_LINE); return make_error("Could not find UID and GID of user '%s'.", cf->servuser); } else if (pw->pw_name == NULL) { @@ -4606,11 +4606,11 @@ static char *install_ds(char *sroot, server_config_s *cf, char *param_name) memset(&slapd_conf, 0, sizeof(SLAPD_CONFIG)); if (sroot) - strcpy(slapd_conf.slapd_server_root, sroot); + PL_strncpyz(slapd_conf.slapd_server_root, sroot, sizeof(slapd_conf.slapd_server_root)); if (cf->servport) slapd_conf.port = atoi(cf->servport); if (cf->servname) - strcpy(slapd_conf.host, cf->servname); + PL_strncpyz(slapd_conf.host, cf->servname, sizeof(slapd_conf.host)); status = config_suitespot(&slapd_conf, &query_vars); if (status == -1) /* invalid or null arguments or configuration */ diff --git a/ldap/admin/src/latest_file.c b/ldap/admin/src/latest_file.c index 41f27d9a..a68ea01b 100644 --- a/ldap/admin/src/latest_file.c +++ b/ldap/admin/src/latest_file.c @@ -56,7 +56,8 @@ int main (int argc, char **argv) szOutput = argv[2]; /* Get directory part of path */ - strcpy( dir, szWildcardFileSpec ); + strncpy( dir, szWildcardFileSpec, sizeof(dir)-1 ); + dir[sizeof(dir)-1] = (char)0; dirEnd = strrchr( dir, '\\' ); if ( dirEnd != NULL ) { *dirEnd = 0; diff --git a/ldap/admin/src/script-gen.c b/ldap/admin/src/script-gen.c index 0f93406a..bc364c9d 100644 --- a/ldap/admin/src/script-gen.c +++ b/ldap/admin/src/script-gen.c @@ -79,7 +79,8 @@ int generate_script(const char *inpath, const char *outpath, int mode, /* not enough room, scratch it */ continue; } - strcpy(save_buffer, q+2); + strncpy(save_buffer, q+2, sizeof(save_buffer)-1); + save_buffer[sizeof(save_buffer)-1] = (char)0; strcpy(p, table[i][1]); strcat(p, save_buffer); q = p; diff --git a/ldap/cm/newinst/ux-config.cc b/ldap/cm/newinst/ux-config.cc index e8a5f0bb..e3fe16a5 100644 --- a/ldap/cm/newinst/ux-config.cc +++ b/ldap/cm/newinst/ux-config.cc @@ -24,6 +24,7 @@ extern "C" { #include <strings.h> #endif #include "nspr.h" +#include "plstr.h" } /* Newer g++ wants the new std header forms */ #if defined( Linux ) @@ -319,7 +320,7 @@ SlapdPreInstall::initDefaultConfig() static char test_host[BIG_BUF] = {0}; struct hostent *hp; - strcpy(test_host,guess_host); + PL_strncpyz(test_host,guess_host,sizeof(test_host)); hp = gethostbyname(test_host); if (hp == NULL) { return -1; @@ -828,17 +829,9 @@ SlapdPreInstall::verifyRemoteLdap( if (!mypwd) mypwd = getBaseScript()->get(binddnpwd); - char *s = (char *)malloc(10 + strlen(myhost) + strlen(myport) + - ((suffix && mysuffix) ? strlen(mysuffix):0)); - strcpy(s, "ldap://"); - strcat(s, myhost); - strcat(s, ":"); - strcat(s, myport); - strcat(s, "/"); - if (suffix && mysuffix) - strcat(s, mysuffix); + char *s = PR_smprintf("ldap://%s:%s/%s", myhost, myport, (suffix && mysuffix) ? mysuffix : ""); int status = authLdapUser(s, mydn, mypwd, NULL, NULL); - free(s); + PR_smprintf_free(s); return status; } @@ -873,15 +866,7 @@ SlapdPreInstall::verifyAdminDomain( if (!myadmin_domain) myadmin_domain = getBaseScript()->get(admin_domain); - char *s = (char *)malloc(10 + strlen(myhost) + strlen(myport) + - ((suffix && mysuffix) ? strlen(mysuffix):0)); - strcpy(s, "ldap://"); - strcat(s, myhost); - strcat(s, ":"); - strcat(s, myport); - strcat(s, "/"); - if (suffix && mysuffix) - strcat(s, mysuffix); + char *s = PR_smprintf("ldap://%s:%s/%s", myhost, myport, (suffix && mysuffix) ? mysuffix : ""); LdapError ldapErr; Ldap ldap(ldapErr, s, mydn, mypwd); int status = ldapErr; @@ -892,7 +877,7 @@ SlapdPreInstall::verifyAdminDomain( status = ad.retrieve(dn); } - free(s); + PR_smprintf_free(s); return status; } @@ -927,7 +912,7 @@ SlapdPreInstall::getDNSDomain() const return NULL; } - strcpy(domain, guess_domain); + PL_strncpyz(domain, guess_domain, sizeof(domain)); return domain; } else { return NULL; @@ -935,7 +920,7 @@ SlapdPreInstall::getDNSDomain() const } ++ptr; - strcpy(domain, ptr); + PL_strncpyz(domain, ptr, sizeof(domain)); return domain; } @@ -951,13 +936,13 @@ SlapdPreInstall::getDefaultSuffix() const return suffix; char *sptr = suffix; - strcat(sptr, SUF); + PL_strcatn(sptr, sizeof(suffix), SUF); sptr += SUF_LEN; for (const char *ptr = getDNSDomain(); ptr && *ptr; *ptr++) { if (*ptr == '.') { - strcat(sptr, ", "); + PL_strcatn(sptr, sizeof(suffix), ", "); sptr += 2; - strcat(sptr, SUF); + PL_strcatn(sptr, sizeof(suffix), SUF); sptr += SUF_LEN; } else { *sptr++ = *ptr; diff --git a/ldap/cm/newinst/ux-dialog.cc b/ldap/cm/newinst/ux-dialog.cc index 7d0db74c..55cb3618 100644 --- a/ldap/cm/newinst/ux-dialog.cc +++ b/ldap/cm/newinst/ux-dialog.cc @@ -42,6 +42,7 @@ using std::ostrstream; extern "C" { #include "dsalib.h" #include "nspr.h" +#include "plstr.h" } static const char *DEFAULT_SLAPDUSER = "cn=Directory Manager"; @@ -335,7 +336,7 @@ askSlapdPortSetup(Dialog *me) if (defPort && *defPort && atoi(defPort) > 0) { - strcpy(tmp, defPort); + PL_strncpyz(tmp, defPort, sizeof(tmp)); port = atoi(defPort); } else diff --git a/ldap/cm/newinst/ux-guesses.cc b/ldap/cm/newinst/ux-guesses.cc index 3323a0a1..e4d9e58d 100644 --- a/ldap/cm/newinst/ux-guesses.cc +++ b/ldap/cm/newinst/ux-guesses.cc @@ -8,9 +8,12 @@ -/* $RCSfile: ux-guesses.cc,v $ $Revision: 1.2 $ $Date: 2005/02/28 23:37:49 $ $State: Exp $ */ +/* $RCSfile: ux-guesses.cc,v $ $Revision: 1.3 $ $Date: 2005/03/11 03:46:41 $ $State: Exp $ */ /* * $Log: ux-guesses.cc,v $ + * Revision 1.3 2005/03/11 03:46:41 rmeggins + * This one is mostly strcpy/strcat checking, checking for null strings before strlen, removing some dead code, other odds and ends. + * * Revision 1.2 2005/02/28 23:37:49 nkinder * 149951 - Updated source code copyrights * @@ -99,7 +102,7 @@ int PrintGuessPreInstall::start() static char test_host[BIG_BUF] = {0}; struct hostent *hp; - strcpy(test_host,hno); + PL_strncpyz(test_host,hno,sizeof(test_host)); hp = gethostbyname(test_host); if (hp == NULL) { printf("addressable: no\n"); diff --git a/ldap/cm/newinstnt/dsinst.c b/ldap/cm/newinstnt/dsinst.c index 8fda4410..5b116382 100644 --- a/ldap/cm/newinstnt/dsinst.c +++ b/ldap/cm/newinstnt/dsinst.c @@ -75,6 +75,13 @@ my_snprintf(char *s, size_t size, const char *fmt, ...) } static void +my_strncpy(char *dst, const char *src, size_t size) +{ + strncpy(dst, src, size-1); + dst[size-1] = (char)0; +} + +static void storeUserDirectoryInfo() { char *utf8UserGroupAdmin = NULL; @@ -90,14 +97,14 @@ storeUserDirectoryInfo() if(mi.m_nExistingMCC == 0) { /* the user is also creating a new MCC so set UG admin to MCC admin */ - lstrcpy(mi.m_szUserGroupAdmin, mi.m_szMCCBindAs); - lstrcpy(mi.m_szUserGroupAdminPW, mi.m_szMCCPw); + my_strncpy(mi.m_szUserGroupAdmin, mi.m_szMCCBindAs, sizeof(mi.m_szUserGroupAdmin)); + my_strncpy(mi.m_szUserGroupAdminPW, mi.m_szMCCPw, sizeof(mi.m_szUserGroupAdminPW)); }else{ /* user is using an existing MCC so only creating UG, make UG user same as Root DN */ - lstrcpy(mi.m_szUserGroupAdmin, mi.m_szInstanceUnrestrictedUser); - lstrcpy(mi.m_szUserGroupAdminPW, mi.m_szInstancePassword); + my_strncpy(mi.m_szUserGroupAdmin, mi.m_szInstanceUnrestrictedUser, sizeof(mi.m_szUserGroupAdmin)); + my_strncpy(mi.m_szUserGroupAdminPW, mi.m_szInstancePassword, sizeof(mi.m_szUserGroupAdminPW)); } my_snprintf(mi.m_szUserGroupURL, sizeof(mi.m_szUserGroupURL), "ldap://%s:%d/%s", mi.m_szInstanceHostName, @@ -420,7 +427,7 @@ int GetURLComponents(char *szURL, char *szHost, int *nPort, char *szBase) if( NULL != ludpp->lud_host) { - strcpy(szHost, ludpp->lud_host); + my_strncpy(szHost, ludpp->lud_host, MAX_STR_SIZE); }else{ strcpy(szHost, "\0"); } @@ -429,7 +436,7 @@ int GetURLComponents(char *szURL, char *szHost, int *nPort, char *szBase) if( NULL != ludpp->lud_dn) { - strcpy(szBase, ludpp->lud_dn); + my_strncpy(szBase, ludpp->lud_dn, MAX_STR_SIZE); }else{ strcpy(szBase, "\0"); } @@ -885,27 +892,27 @@ int set_default_ldap_settings() mi.m_nUseChangeLogSettings = 0; - lstrcpy(mi.m_szSIRDays, DEFAULT_SIR_DAYS); - lstrcpy(mi.m_szSIRTimes, DEFAULT_SIR_TIMES); + my_strncpy(mi.m_szSIRDays, DEFAULT_SIR_DAYS, sizeof(mi.m_szSIRDays)); + my_strncpy(mi.m_szSIRTimes, DEFAULT_SIR_TIMES, sizeof(mi.m_szSIRTimes)); mi.m_nSupplierPort = DEFAULT_SERVER_PORT; - lstrcpy(mi.m_szCIRDays, DEFAULT_CIR_DAYS); - lstrcpy(mi.m_szCIRTimes, DEFAULT_CIR_TIMES); + my_strncpy(mi.m_szCIRDays, DEFAULT_CIR_DAYS, sizeof(mi.m_szCIRDays)); + my_strncpy(mi.m_szCIRTimes, DEFAULT_CIR_TIMES, sizeof(mi.m_szCIRTimes)); mi.m_nConsumerPort = DEFAULT_SERVER_PORT; mi.m_nCIRInterval = DEFAULT_CIR_INTERVAL; /* default MCC settings */ - lstrcpy(mi.m_szMCCSuffix, NS_DOMAIN_ROOT); + my_strncpy(mi.m_szMCCSuffix, NS_DOMAIN_ROOT, sizeof(mi.m_szMCCSuffix)); mi.m_nMCCPort=DEFAULT_SERVER_PORT; mi.m_szMCCBindAs = malloc(MAX_STR_SIZE); my_snprintf(mi.m_szMCCBindAs, sizeof(mi.m_szMCCBindAs), "%s", DEFAULT_SSPT_USER); - lstrcpy(mi.m_szUGSuffix, mi.m_szInstanceSuffix); + my_strncpy(mi.m_szUGSuffix, mi.m_szInstanceSuffix, sizeof(mi.m_szUGSuffix)); mi.m_nUGPort=DEFAULT_SERVER_PORT; - lstrcpy(mi.m_szUserGroupAdmin, DEFAULT_UNRESTRICTED_USER); + my_strncpy(mi.m_szUserGroupAdmin, DEFAULT_UNRESTRICTED_USER, sizeof(mi.m_szUserGroupAdmin)); mi.m_nPopulateSampleEntries = DEFAULT_POPULATE_SAMPLE_ENTRIES; mi.m_nDisableSchemaChecking = DEFAULT_DISABLE_SCHEMA_CHECKING; @@ -961,11 +968,11 @@ void set_ldap_settings() /* this new instance will be MCC, but only copy over things if not silent mode, in silent mode it will read correct mcc stuff from the cache */ - lstrcpy(mi.m_szMCCHost, mi.m_szInstanceHostName); + my_strncpy(mi.m_szMCCHost, mi.m_szInstanceHostName, sizeof(mi.m_szMCCHost)); mi.m_nMCCPort = mi.m_nInstanceServerPort; - lstrcpy(mi.m_szMCCSuffix, NS_DOMAIN_ROOT); + my_strncpy(mi.m_szMCCSuffix, NS_DOMAIN_ROOT, sizeof(mi.m_szMCCSuffix)); my_snprintf(mi.m_szMCCBindAs, sizeof(mi.m_szMCCBindAs), "%s", mi.m_szSsptUid); - lstrcpy(mi.m_szMCCPw, mi.m_szSsptUidPw); + my_strncpy(mi.m_szMCCPw, mi.m_szSsptUidPw, sizeof(mi.m_szMCCPw)); } @@ -2581,7 +2588,7 @@ Server_Settings_DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam SendDlgItemMessage(hwndDlg, IDC_SPIN_SERVER_PORT, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_EDIT_SERVER_PORT), 0); SendDlgItemMessage(hwndDlg, IDC_SPIN_SERVER_PORT, UDM_SETRANGE, 0, MAKELONG((short)UD_MAXVAL, (short)1)); - lstrcpy(szSavedSuffix, mi.m_szInstanceSuffix); + my_strncpy(szSavedSuffix, mi.m_szInstanceSuffix, sizeof(szSavedSuffix)); break; @@ -2621,12 +2628,12 @@ Server_Settings_DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam /* hide suffix when creating config only directory */ if( 0 != strlen(mi.m_szInstanceSuffix) ) { - lstrcpy(szSavedSuffix, mi.m_szInstanceSuffix); + my_strncpy(szSavedSuffix, mi.m_szInstanceSuffix, sizeof(szSavedSuffix)); memset(mi.m_szInstanceSuffix, '\0', MAX_STR_SIZE); } nCmdShow = SW_HIDE; }else{ - lstrcpy(mi.m_szInstanceSuffix, szSavedSuffix); + my_strncpy(mi.m_szInstanceSuffix, szSavedSuffix, sizeof(mi.m_szInstanceSuffix)); nCmdShow = SW_SHOW; } @@ -2688,7 +2695,7 @@ Server_Settings_DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam // NOTE: To prevent the wizard from stepping back, return -1. SaveDialogInput_Server_Settings(hwndDlg); // save the suffix typed in by the user - lstrcpy(szSavedSuffix, mi.m_szInstanceSuffix); + my_strncpy(szSavedSuffix, mi.m_szInstanceSuffix, sizeof(szSavedSuffix)); break; case PSN_WIZNEXT: @@ -2701,7 +2708,7 @@ Server_Settings_DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam // NOTE: To prevent the wizard from stepping ahead, return -1. SaveDialogInput_Server_Settings(hwndDlg); // save the suffix typed in by the user - lstrcpy(szSavedSuffix, mi.m_szInstanceSuffix); + my_strncpy(szSavedSuffix, mi.m_szInstanceSuffix, sizeof(szSavedSuffix)); if( TRUE == (bValueReturned = Verify_Server_Settings()) ) { /* one of the settings was invalid stay on this page */ @@ -5692,14 +5699,14 @@ DSINST_PreInstall(LPCSTR lpszInstallPath) &szAdminDomain); if (szLdapURL && szAdminDomain) { - lstrcpy(mi.m_szLdapURL, szLdapURL); + my_strncpy(mi.m_szLdapURL, szLdapURL, sizeof(mi.m_szLdapURL)); GetURLComponents(mi.m_szLdapURL, mi.m_szMCCHost, &mi.m_nMCCPort, mi.m_szMCCSuffix); if (mi.m_szMCCSuffix[0] == 0) - lstrcpy(mi.m_szMCCSuffix, NS_DOMAIN_ROOT); + my_strncpy(mi.m_szMCCSuffix, NS_DOMAIN_ROOT, sizeof(mi.m_szMCCSuffix)); if (szLdapUser && mi.m_szMCCBindAs) - lstrcpy(mi.m_szMCCBindAs, szLdapUser); - lstrcpy(mi.m_szAdminDomain, szAdminDomain); + my_strncpy(mi.m_szMCCBindAs, szLdapUser, sizeof(mi.m_szMCCBindAs)); + my_strncpy(mi.m_szAdminDomain, szAdminDomain, sizeof(mi.m_szAdminDomain)); // since this server root is already configured to use // an existing configuration directory server, we will // not allow the user to install another one here, so @@ -6085,14 +6092,14 @@ DSINST_WriteGlobalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) if(mi.m_nExistingMCC == 0) { /* the user is also creating a new MCC so set UG admin to MCC admin */ - lstrcpy(mi.m_szUserGroupAdmin, mi.m_szMCCBindAs); - lstrcpy(mi.m_szUserGroupAdminPW, mi.m_szMCCPw); + my_strncpy(mi.m_szUserGroupAdmin, mi.m_szMCCBindAs, sizeof(mi.m_szUserGroupAdmin)); + my_strncpy(mi.m_szUserGroupAdminPW, mi.m_szMCCPw, sizeof(mi.m_szUserGroupAdminPW)); }else{ /* user is using an existing MCC so only creating UG, make UG user same as Root DN */ - lstrcpy(mi.m_szUserGroupAdmin, mi.m_szInstanceUnrestrictedUser); - lstrcpy(mi.m_szUserGroupAdminPW, mi.m_szInstancePassword); + my_strncpy(mi.m_szUserGroupAdmin, mi.m_szInstanceUnrestrictedUser, sizeof(mi.m_szUserGroupAdmin)); + my_strncpy(mi.m_szUserGroupAdminPW, mi.m_szInstancePassword, sizeof(mi.m_szUserGroupAdminPW)); } my_snprintf(mi.m_szUserGroupURL, sizeof(mi.m_szUserGroupURL), "ldap://%s:%d/%s", mi.m_szInstanceHostName, @@ -6390,7 +6397,7 @@ DSINST_ReadGlobalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) /* stevross: now that cgi can handle full DN Sspt UID is same user as MCC BindAs no matter what look into removing later once get instance creatin working */ - lstrcpy(mi.m_szSsptUid, mi.m_szMCCBindAs); + my_strncpy(mi.m_szSsptUid, mi.m_szMCCBindAs, sizeof(mi.m_szSsptUid)); } GetPrivateProfileString(lpszSectionName, GLOBAL_INF_LDAP_PASSWD, "\0", @@ -6403,8 +6410,8 @@ DSINST_ReadGlobalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) return FALSE; }else{ /* use password for sspt user since this is the ssptuser */ - lstrcpy(mi.m_szSsptUidPw, mi.m_szMCCPw); - lstrcpy(mi.m_szSsptUidPwAgain, mi.m_szSsptUidPw); + my_strncpy(mi.m_szSsptUidPw, mi.m_szMCCPw, sizeof(mi.m_szSsptUidPw)); + my_strncpy(mi.m_szSsptUidPwAgain, mi.m_szSsptUidPw, sizeof(mi.m_szSsptUidPwAgain)); } GetPrivateProfileString(lpszSectionName, SLAPD_KEY_ADMIN_DOMAIN, "\0", @@ -6454,7 +6461,7 @@ DSINST_ReadGlobalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) /* stevross: now that cgi can handle full DN Sspt UID is same user as MCC BindAs no matter what look into removing later once get instance creatin working */ - lstrcpy(mi.m_szSsptUid, mi.m_szMCCBindAs); + my_strncpy(mi.m_szSsptUid, mi.m_szMCCBindAs, sizeof(mi.m_szSsptUid)); } GetPrivateProfileString(lpszSectionName, GLOBAL_INF_LDAP_PASSWD, "\0", @@ -6467,8 +6474,8 @@ DSINST_ReadGlobalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) return FALSE; }else{ /* use password for sspt user since this is the ssptuser */ - lstrcpy(mi.m_szSsptUidPw, mi.m_szMCCPw); - lstrcpy(mi.m_szSsptUidPwAgain, mi.m_szSsptUidPw); + my_strncpy(mi.m_szSsptUidPw, mi.m_szMCCPw, sizeof(mi.m_szSsptUidPw)); + my_strncpy(mi.m_szSsptUidPwAgain, mi.m_szSsptUidPw, sizeof(mi.m_szSsptUidPwAgain)); } GetPrivateProfileString(lpszSectionName, SLAPD_KEY_ADMIN_DOMAIN, "\0", @@ -6569,7 +6576,7 @@ DSINST_ReadLocalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) mi.m_szInstancePassword, MAX_STR_SIZE, lpszCacheFileName); - lstrcpy(mi.m_szInstancePasswordAgain, mi.m_szInstancePassword); + my_strncpy(mi.m_szInstancePasswordAgain, mi.m_szInstancePassword, sizeof(mi.m_szInstancePasswordAgain)); GetPrivateProfileString(lpszSectionName, SLAPD_KEY_SERVER_IDENTIFIER, "\0", @@ -6659,7 +6666,7 @@ DSINST_ReadLocalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) lpszCacheFileName); /* read from cache, so copy it to mi.m_szSupplierPWAgain); */ - lstrcpy(mi.m_szSupplierPWAgain, mi.m_szSupplierPW); + my_strncpy(mi.m_szSupplierPWAgain, mi.m_szSupplierPW, sizeof(mi.m_szSupplierPWAgain)); /* Supplier replication settings */ @@ -6734,7 +6741,7 @@ DSINST_ReadLocalCache(LPCSTR lpszCacheFileName, LPCSTR lpszSectionName) mi.m_szConsumerPW, MAX_STR_SIZE, lpszCacheFileName); - lstrcpy(mi.m_szConsumerPWAgain, mi.m_szConsumerPW); + my_strncpy(mi.m_szConsumerPWAgain, mi.m_szConsumerPW, sizeof(mi.m_szConsumerPWAgain)); GetPrivateProfileString(lpszSectionName, SLAPD_KEY_INSTALL_LDIF_FILE, DEFAULT_INF_POP_LDIF_FILE, mi.m_szPopLdifFile, MAX_STR_SIZE, @@ -7006,15 +7013,15 @@ create_slapd_instance(const char *hostname, const char *serverroot) serverroot); if (mi.m_nReInstall) { - strcat(szCGIArgs, " -r -f "); + PL_strcatn(szCGIArgs, sizeof(szCGIArgs), " -r -f "); /* add the -r flag if reinstalling */ } else { - strcat(szCGIArgs, " -f "); + PL_strcatn(szCGIArgs, sizeof(szCGIArgs), " -f "); } - strcat(szCGIArgs, "\""); - strcat(szCGIArgs, INFfile); - strcat(szCGIArgs, "\""); + PL_strcatn(szCGIArgs, sizeof(szCGIArgs), "\""); + PL_strcatn(szCGIArgs, sizeof(szCGIArgs), INFfile); + PL_strcatn(szCGIArgs, sizeof(szCGIArgs), "\""); myLogData("create_slapd_instance: executing %s %s", PERL_EXE, szCGIArgs); status = run_cgi(serverroot, PERL_EXE, szCGIArgs); @@ -7305,7 +7312,7 @@ updateRegistryKeys(const char *oldVersion, const char *newVersion) my_snprintf(newKey, sizeof(newKey), "%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT); strcpy(oldKey, newKey); if (ptr = strstr(oldKey, SVR_VERSION)) { - strncpy(ptr, oldVersion, strlen(oldVersion)); + my_strncpy(ptr, oldVersion, strlen(oldVersion)); } myLogData("updateRegistryKeys: copying %s to %s\n", diff --git a/ldap/servers/plugins/acl/acl.c b/ldap/servers/plugins/acl/acl.c index 4e21c31d..23f41240 100644 --- a/ldap/servers/plugins/acl/acl.c +++ b/ldap/servers/plugins/acl/acl.c @@ -1712,11 +1712,7 @@ acl_modified (Slapi_PBlock *pb, int optype, char *n_dn, void *change) if (parent_DN == NULL) { new_DN = new_RDN; } else { - new_DN = (char*) slapi_ch_malloc (strlen (new_RDN) + 3 - + strlen (parent_DN)); - strcpy (new_DN, new_RDN); - strcat (new_DN, ","); - strcat (new_DN, parent_DN); + new_DN = slapi_ch_smprintf("%s,%s", new_RDN, parent_DN); slapi_dn_normalize (new_DN); } diff --git a/ldap/servers/plugins/acl/aclutil.c b/ldap/servers/plugins/acl/aclutil.c index 8971c4f2..0705c419 100644 --- a/ldap/servers/plugins/acl/aclutil.c +++ b/ldap/servers/plugins/acl/aclutil.c @@ -539,8 +539,10 @@ aclutil_expand_paramString ( char *str, Slapi_Entry *e ) } rc = 0; /* everything is okay*/ /* remove the last comma */ - len = strlen ( buf); - buf[len-1] = '\0'; + if (buf) { + len = strlen ( buf); + buf[len-1] = '\0'; + } cleanup: diff --git a/ldap/servers/plugins/collation/collate.c b/ldap/servers/plugins/collation/collate.c index c5dfdf89..1345f0bd 100644 --- a/ldap/servers/plugins/collation/collate.c +++ b/ldap/servers/plugins/collation/collate.c @@ -103,9 +103,9 @@ collation_config (size_t cargc, char** cargv, if(cargc > 7) { strcpy(nameOrder,"-"); - PL_strcatn(nameOrder,256,cargv[7]); + PL_strcatn(nameOrder,sizeof(nameOrder),cargv[7]); strcpy(nameSubstring,"-"); - PL_strcatn(nameSubstring,256,cargv[7]); + PL_strcatn(nameSubstring,sizeof(nameSubstring),cargv[7]); slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_NAME, (void *)slapi_ch_strdup(nameOrder)); } @@ -117,19 +117,19 @@ collation_config (size_t cargc, char** cargv, nameOrder[0] = 0; nameSubstring[0] = 0; } - PL_strcatn(nameOrder,256,cargv[1]); - PL_strcatn(nameSubstring,256,cargv[1]); + PL_strcatn(nameOrder,sizeof(nameOrder),cargv[1]); + PL_strcatn(nameSubstring,sizeof(nameSubstring),cargv[1]); slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_NAME, (void *)slapi_ch_strdup(nameOrder)); } - PL_strncpyz(oidString,cargv[6], 256); + PL_strncpyz(oidString,cargv[6], sizeof(oidString)); slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_OID, (void *)slapi_ch_strdup(oidString)); if(0 != cargv[2][0]) { - PR_snprintf(descStr, 256, "%s-%s",cargv[1],cargv[2]); + PR_snprintf(descStr, sizeof(descStr), "%s-%s",cargv[1],cargv[2]); } else { - PL_strncpyz(descStr,cargv[1], 256); + PL_strncpyz(descStr,cargv[1], sizeof(descStr)); } slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_DESC, (void *)slapi_ch_strdup(descStr)); @@ -144,7 +144,7 @@ collation_config (size_t cargc, char** cargv, slapi_ch_free((void **)&tmpStr); slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_NAME, (void *)slapi_ch_strdup(nameSubstring)); - strcat(oidString,".6"); + PL_strcatn(oidString,sizeof(oidString),".6"); slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_OID, (void *)slapi_ch_strdup(oidString)); slapi_matchingrule_register(mrentry); diff --git a/ldap/servers/plugins/cos/cos_cache.c b/ldap/servers/plugins/cos/cos_cache.c index 303458e5..672bb827 100644 --- a/ldap/servers/plugins/cos/cos_cache.c +++ b/ldap/servers/plugins/cos/cos_cache.c @@ -1970,7 +1970,7 @@ static int cos_cache_add_tmpl(cosTemplates **pTemplates, cosAttrValue *dn, cosAt { char tmpGrade[BUFSIZ]; - if (strlen(pCosSpecifier->val) < (BUFSIZ - 9)) { /* 9 for "-default" */ + if (strlen(pCosSpecifier->val) < (sizeof(tmpGrade) - 9)) { /* 9 for "-default" */ strcpy(tmpGrade, pCosSpecifier->val); strcat(tmpGrade, "-default"); if(!slapi_utf8casecmp((unsigned char*)grade, (unsigned char*)tmpGrade)) diff --git a/ldap/servers/plugins/http/http_impl.c b/ldap/servers/plugins/http/http_impl.c index e6d4a664..8c216775 100644 --- a/ldap/servers/plugins/http/http_impl.c +++ b/ldap/servers/plugins/http/http_impl.c @@ -226,11 +226,6 @@ static int doRequest(const char *url, httpheader **httpheaderArray, char *body, PRInt32 errcode = 0; PRInt32 http_connection_time_out = 0; PRInt32 sslOn; - PRInt32 nssStatus; - PRUint32 nssFlags = 0; - char certDir[1024]; - char certPref[1024]; - char keyPref[1024]; LDAPDebug( LDAP_DEBUG_PLUGIN, "--> doRequest -- BEGIN\n",0,0,0); @@ -290,10 +285,16 @@ static int doRequest(const char *url, httpheader **httpheaderArray, char *body, if (!httpConfig->nssInitialized) { if (nssReinitializationRequired()) { + PRInt32 nssStatus; + PRUint32 nssFlags = 0; + char certDir[1024]; + char certPref[1024]; + char keyPref[1024]; + NSS_Shutdown(); nssFlags &= (~NSS_INIT_READONLY); val = config_get_instancedir(); - strcpy(certDir, val); + PL_strncpyz(certDir, val, sizeof(certDir)); defaultprefix = strrchr(certDir, '/'); if (!defaultprefix) defaultprefix = strrchr(certDir, '\\'); @@ -301,7 +302,7 @@ static int doRequest(const char *url, httpheader **httpheaderArray, char *body, goto bail; /* . . . can't do anything */ defaultprefix++; PR_snprintf(certPref, 1024, "%s-",defaultprefix); - strcpy(keyPref, certPref); + PL_strncpyz(keyPref, certPref, sizeof(keyPref)); *defaultprefix= '\0'; PR_snprintf(certDir, 1024, "%salias", certDir); nssStatus = NSS_Initialize(certDir, certPref, keyPref, "secmod.db", nssFlags); @@ -719,7 +720,11 @@ static PRStatus sendPostReq(PRFileDesc *fd, const char *path, httpheader **httph int i = 0; int body_len, buflen = 0; - body_len = strlen(body); + if (body) { + body_len = strlen(body); + } else { + body_len = 0; + } PR_snprintf(body_len_str, sizeof(body_len_str), "%d", body_len); buflen = (HTTP_POST_STD_LEN + strlen(path) + body_len + strlen(body_len_str)); @@ -762,7 +767,9 @@ static PRStatus sendPostReq(PRFileDesc *fd, const char *path, httpheader **httph } strcat(reqBUF, "\r\n"); - strcat(reqBUF, body); + if (body) { + strcat(reqBUF, body); + } strcat(reqBUF, "\0"); LDAPDebug( LDAP_DEBUG_PLUGIN, "---------->reqBUF is %s \n",reqBUF,0,0); diff --git a/ldap/servers/plugins/pam_passthru/pam_ptimpl.c b/ldap/servers/plugins/pam_passthru/pam_ptimpl.c index 8711513f..5103875c 100644 --- a/ldap/servers/plugins/pam_passthru/pam_ptimpl.c +++ b/ldap/servers/plugins/pam_passthru/pam_ptimpl.c @@ -19,7 +19,8 @@ typedef struct my_str_buf { static char * init_my_str_buf(MyStrBuf *buf, const char *s) { - if (s && (strlen(s) < MY_STATIC_BUF_SIZE)) { + PR_ASSERT(buf); + if (s && (strlen(s) < sizeof(buf->fixbuf))) { strcpy(buf->fixbuf, s); buf->str = buf->fixbuf; } else { diff --git a/ldap/servers/plugins/replication/cl5_api.c b/ldap/servers/plugins/replication/cl5_api.c index 4ff55802..cdf371cb 100644 --- a/ldap/servers/plugins/replication/cl5_api.c +++ b/ldap/servers/plugins/replication/cl5_api.c @@ -2387,7 +2387,7 @@ static int _cl5Entry2DBData (const CL5Entry *entry, char **data, PRUint32 *len) char *rawDN = NULL; char s[CSN_STRSIZE]; - PR_ASSERT (entry && entry->op && data && len); + PR_ASSERT (entry && entry->op && data && len && op->target_address.uniqueid); op = entry->op; diff --git a/ldap/servers/plugins/replication/repl_monitor.c b/ldap/servers/plugins/replication/repl_monitor.c index 9e44a93e..1cb10d7f 100644 --- a/ldap/servers/plugins/replication/repl_monitor.c +++ b/ldap/servers/plugins/replication/repl_monitor.c @@ -46,6 +46,7 @@ repl_monitor_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, i { port= config_get_secureport(); } + buf[0] = (char)0; /* ONREPL - how do we publish changenumbers now with multiple changelogs? sprintf( buf, "%s:%lu %s% lu", get_localhost_DNS(), port, sdv, ldapi_get_last_changenumber()); */ diff --git a/ldap/servers/plugins/replication/repl_opext.c b/ldap/servers/plugins/replication/repl_opext.c index b8d117ee..361ecbc8 100644 --- a/ldap/servers/plugins/replication/repl_opext.c +++ b/ldap/servers/plugins/replication/repl_opext.c @@ -12,9 +12,6 @@ /* ***** Supplier side ***** */ -/* JCMREPL -> PINAKIxxx The interface to the referral stuff is not correct */ -void ref_array_dup_free(void *the_copy); /* JCMREPL - should be #included */ - /* supplier operation extension constructor */ void* supplier_operation_extension_constructor (void *object, void *parent) { @@ -89,7 +86,8 @@ void consumer_operation_extension_destructor (void *ext,void *object, void *pare consumer_operation_extension *opext = (consumer_operation_extension *)ext; if (NULL != opext->search_referrals) { - ref_array_dup_free(opext->search_referrals); /* JCMREPL - undefined */ + /* free them - search_referrals is currently unused, but + free them using the obverse of the allocation method */ opext->search_referrals = NULL; } slapi_ch_free((void **)&ext); diff --git a/ldap/servers/plugins/uiduniq/uid.c b/ldap/servers/plugins/uiduniq/uid.c index e8698a68..312196e1 100644 --- a/ldap/servers/plugins/uiduniq/uid.c +++ b/ldap/servers/plugins/uiduniq/uid.c @@ -19,6 +19,7 @@ #include <string.h> #include "dirver.h" #include "plugin-utils.h" +#include "nspr.h" #if defined( LDAP_DEBUG ) && !defined( DEBUG ) #define DEBUG @@ -114,6 +115,8 @@ create_filter(const char *attribute, const struct berval *value) int valueLen; int filterLen; + PR_ASSERT(attribute); + /* Compute the length of the required buffer */ attrLen = strlen(attribute); diff --git a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c index 63826abb..9c7d4b54 100644 --- a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c +++ b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c @@ -72,9 +72,9 @@ static char *attrinfo2ConfMatchingRules (struct attrinfo *pai) if (pai->ai_index_rules) { strcat (buffer, "\t"); for (i = 0; pai->ai_index_rules[i]; i++) { - strcat (buffer, pai->ai_index_rules[i]); + PL_strcatn (buffer, sizeof(buffer), pai->ai_index_rules[i]); if (pai->ai_index_rules[i+1]) { - strcat (buffer, ","); + PL_strcatn (buffer, sizeof(buffer), ","); } } } @@ -500,13 +500,13 @@ int ldbm_instance_config_add_index_entry( return(-1); } - PL_strncpyz(tmpAttrsStr,argv[0], 256); + PL_strncpyz(tmpAttrsStr,argv[0], sizeof(tmpAttrsStr)); attrs = str2charray( tmpAttrsStr, "," ); - PL_strncpyz(tmpIndexesStr,argv[1], 256); + PL_strncpyz(tmpIndexesStr,argv[1], sizeof(tmpIndexesStr)); indexes = str2charray( tmpIndexesStr, ","); if(argc > 2) { - PL_strncpyz(tmpMatchingRulesStr,argv[2], 1024); + PL_strncpyz(tmpMatchingRulesStr,argv[2], sizeof(tmpMatchingRulesStr)); matchingRules = str2charray( tmpMatchingRulesStr, ","); } diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c index 65f1a6f0..f800f7c5 100644 --- a/ldap/servers/slapd/back-ldbm/ldbm_search.c +++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c @@ -757,18 +757,6 @@ onelevel_candidates( return( candidates ); } - -#define GRABSIZE2 50 -#define BUF_ALLOC_CAT( cpyfunc, s ) { \ - int len = 2 * strlen( s ); \ - while ( bmax - bcur < len + 1 ) { \ - bmax += GRABSIZE2; \ - buf = slapi_ch_realloc( buf, bmax ); \ - } \ - cpyfunc( buf + bcur, s ); \ - bcur += strlen( buf + bcur ); \ -} - /* * We need to modify the filter to be something like this: * diff --git a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c index 2e3d1d8d..4ec954d4 100644 --- a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c +++ b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c @@ -85,14 +85,14 @@ int ldbm_back_fetch_incl_excl(Slapi_PBlock *pb, char ***include, /* normalize */ if (pb_excl) { for (i = 0; pb_excl[i]; i++) { - PL_strncpyz(subtreeDn, pb_excl[i], BUFSIZ); + PL_strncpyz(subtreeDn, pb_excl[i], sizeof(subtreeDn)); normSubtreeDn = slapi_dn_normalize_case(subtreeDn); charray_add(exclude, slapi_ch_strdup(normSubtreeDn)); } } if (pb_incl) { for (i = 0; pb_incl[i]; i++) { - PL_strncpyz(subtreeDn, pb_incl[i], BUFSIZ); + PL_strncpyz(subtreeDn, pb_incl[i], sizeof(subtreeDn)); normSubtreeDn = slapi_dn_normalize_case(subtreeDn); charray_add(include, slapi_ch_strdup(normSubtreeDn)); } diff --git a/ldap/servers/slapd/back-ldbm/uniqueid2entry.c b/ldap/servers/slapd/back-ldbm/uniqueid2entry.c index c743de54..5319d706 100644 --- a/ldap/servers/slapd/back-ldbm/uniqueid2entry.c +++ b/ldap/servers/slapd/back-ldbm/uniqueid2entry.c @@ -34,6 +34,7 @@ uniqueid2entry( #endif if (e == NULL) { /* convert dn to entry id */ + PR_ASSERT(uniqueid); *err = 0; idv.bv_val = (void*)uniqueid; idv.bv_len = strlen( idv.bv_val ); diff --git a/ldap/servers/slapd/back-ldbm/vlv_srch.c b/ldap/servers/slapd/back-ldbm/vlv_srch.c index 42012af1..e7d7d608 100644 --- a/ldap/servers/slapd/back-ldbm/vlv_srch.c +++ b/ldap/servers/slapd/back-ldbm/vlv_srch.c @@ -57,12 +57,14 @@ vlvSearch_new() static void trimspaces(char *s) { - PRUint32 i= strlen(s) - 1; - while(i > 0 && isascii(s[i]) && isspace(s[i])) - { - s[i]= '\0'; - i--; - } + if (s) { + PRUint32 i= strlen(s) - 1; + while(i > 0 && isascii(s[i]) && isspace(s[i])) + { + s[i]= '\0'; + i--; + } + } } /* diff --git a/ldap/servers/slapd/backend_manager.c b/ldap/servers/slapd/backend_manager.c index 842d2a55..e7a085d9 100644 --- a/ldap/servers/slapd/backend_manager.c +++ b/ldap/servers/slapd/backend_manager.c @@ -379,259 +379,6 @@ be_nbackends_public() #define SUFFIX_ATTR "nsslapd-suffix" #define CACHE_ATTR "nsslapd-cachememsize" -/* add nsslapd-instance attribute to cn=config,cn=ldbm database,cn=plugins,cn=config - entry. This causes empty backend instance creation */ -/* JCM - Should be adding an instance entry, not an attr value */ -static int -be_add_instance (const char *name, void *plugin_identity) -{ - Slapi_PBlock pb; - Slapi_Mods smods; - int rc; - - PR_ASSERT (name && plugin_identity); - - slapi_mods_init (&smods, 1); - slapi_mods_add(&smods, LDAP_MOD_ADD, INSTANCE_ATTR, strlen (name), name); - - pblock_init (&pb); - slapi_modify_internal_set_pb (&pb, LDBM_CONFIG_ENTRY, - slapi_mods_get_ldapmods_byref(&smods), NULL, - NULL, plugin_identity, 0); - slapi_modify_internal_pb (&pb); - slapi_mods_done (&smods); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT,&rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to modify ldbm configuration entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - - pblock_done(&pb); - return 0; -} - -static char* -be_get_instance_dn (const char *index_name, const char *name) -{ - char *dn; - - PR_ASSERT (name); - - if (index_name) { - dn = slapi_ch_smprintf("cn=%s,cn=index,cn=config,cn=%s,%s", index_name, name, - LDBM_CLASS_PREFIX); - } else { - dn = slapi_ch_smprintf("cn=config,cn=%s,%s", name, LDBM_CLASS_PREFIX); - } - - return dn; -} - - -/* configure newly added backend by modifying instance's configuration entry: - cn=config,cn=<instance name>,cn=ldbm database,cn=plugins,cn=config. - Can configure backend root and cache size */ -static int -be_configure_instance (const char *name, const char *root, int cache_size, - void *plugin_identity) -{ - Slapi_PBlock pb; - Slapi_Mods smods; - char value [128]; - char *dn; - int rc; - - PR_ASSERT (name && root && plugin_identity); - - dn = be_get_instance_dn (NULL, name); - - slapi_mods_init (&smods, 2); - slapi_mods_add(&smods, LDAP_MOD_ADD, SUFFIX_ATTR, strlen (root), root); - if (cache_size > 0) - { - sprintf (value, "%d", cache_size); - slapi_mods_add(&smods, LDAP_MOD_REPLACE, CACHE_ATTR, strlen (value), value); - } - - pblock_init (&pb); - slapi_modify_internal_set_pb (&pb, dn, slapi_mods_get_ldapmods_byref(&smods), - NULL, NULL, plugin_identity, 0); - slapi_modify_internal_pb (&pb); - - slapi_mods_done (&smods); - slapi_ch_free ((void**)&dn); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to update instance entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - - pblock_done(&pb); - return 0; -} - -/* configure instance indexes by adding an index entry: - "cn=<attr name>,cn=index,cn=config,cn=<instance name>, - cn=ldbm database,cn=plugins,cn=config".*/ -static int -be_configure_instance_indexes (const char *name, IndexConfig *indexes, - int index_count, void *plugin_identity) -{ - int rc; - Slapi_PBlock pb; - Slapi_Entry *e; - char *dn; - int i; - char *start, *end; - char index_type [16]; - - PR_ASSERT (name && indexes && index_count > 0 && plugin_identity); - - for (i = 0; i < index_count; i++) - { - dn = be_get_instance_dn (indexes[i].attr_name, name); - e = slapi_entry_alloc (); - slapi_entry_init (e, dn, NULL); - - /* add objectclases */ - slapi_entry_add_string (e, "objectclass", "top"); - slapi_entry_add_string (e, "objectclass", "nsIndex"); - slapi_entry_add_string (e, "cn", indexes[i].attr_name); - slapi_entry_add_string (e, "nssystemindex", indexes[i].system ? "true" : "false"); - - start = indexes[i].index_type; - while ((end = strchr (start, ' ')) != NULL) - { - if ((end - start) >= 16) - continue; - - strncpy (index_type, start, end - start); - slapi_entry_add_string (e, "nsindextype", index_type); - start = end + 1; - } - - slapi_entry_add_string (e, "nsindextype", start); - - pblock_init (&pb); - slapi_add_entry_internal_set_pb (&pb, e, NULL /* controls */, plugin_identity, - 0/* operation flags */); - slapi_add_internal_pb (&pb); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to update instance entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - } - - pblock_done(&pb); - return 0; -} - -int -be_create_instance (const char *type, const char *name, const char *root, - int cache_size, IndexConfig *indexes, int index_count, - void *plugin_identity) -{ - int rc; - - if (type == NULL || strcasecmp (type, "ldbm") != 0) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "invalid backend type: %s.\n", type ? type : "null"); - return -1; - } - - if (name == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: null instance name.\n"); - return -1; - } - - if (root == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: null root dn.\n"); - return -1; - } - - if (plugin_identity == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: null plugin identity.\n"); - return -1; - } - - rc = be_add_instance (name, plugin_identity); - if (rc != 0) - return rc; - - rc = be_configure_instance (name, root, cache_size, plugin_identity); - if (rc != 0) - return rc; - - if (index_count > 0) - rc = be_configure_instance_indexes (name, indexes, index_count, plugin_identity); - - return rc; -} - -int -be_remove_instance (const char *type, const char *name, void *plugin_identity) -{ - int rc; - char *dn; - Slapi_PBlock pb; - - if (type == NULL || strcasecmp (type, "ldbm") != 0) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_remove_instance: " - "invalid backend type: %s.\n", type ? type : "null"); - return -1; - } - - if (name == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_remove_instance: null instance name.\n"); - return -1; - } - - if (plugin_identity == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_remove_instance: null plugin identity.\n"); - return -1; - } - - dn = be_get_instance_dn (NULL, name); - - pblock_init (&pb); - slapi_delete_internal_set_pb (&pb, dn, NULL, NULL, plugin_identity, 0); - slapi_delete_internal_pb (&pb); - - slapi_ch_free ((void**)&dn); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to update instance entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - - pblock_done(&pb); - return 0; -} - void slapi_be_Rlock(Slapi_Backend * be) { @@ -680,6 +427,8 @@ slapi_lookup_instance_name_by_suffix(char *suffix, if (instances == NULL) return rval; + PR_ASSERT(suffix); + rval = 0; suffixlen = strlen(suffix); cookie = NULL; diff --git a/ldap/servers/slapd/ch_malloc.c b/ldap/servers/slapd/ch_malloc.c index e64bdb3d..d673159d 100644 --- a/ldap/servers/slapd/ch_malloc.c +++ b/ldap/servers/slapd/ch_malloc.c @@ -383,9 +383,14 @@ slapi_ch_smprintf(const char *fmt, ...) char *p = NULL; va_list ap; + if (NULL == fmt) { + return NULL; + } + va_start(ap, fmt); p = PR_vsmprintf(fmt, ap); va_end(ap); + return p; } diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c index d1166054..15c10213 100644 --- a/ldap/servers/slapd/dn.c +++ b/ldap/servers/slapd/dn.c @@ -817,10 +817,7 @@ char * slapi_dn_plus_rdn(const char *dn, const char *rdn) { /* rdn + separator + dn + null */ - char *newdn = (char *) slapi_ch_malloc( strlen( dn ) + strlen( rdn ) + 2 ); - strcpy( newdn, rdn ); - strcat( newdn, "," ); - strcat( newdn, dn ); + char *newdn = slapi_ch_smprintf("%s,%s", rdn, dn); return newdn; } diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c index 0989b37f..51feb61e 100644 --- a/ldap/servers/slapd/entry.c +++ b/ldap/servers/slapd/entry.c @@ -2215,11 +2215,16 @@ slapi_entry_attr_set_charptr( Slapi_Entry* e, const char *type, const char *valu { struct berval bv; struct berval *bvals[2]; - bvals[0] = &bv; - bvals[1] = NULL; - bv.bv_val = (char*)value; - bv.bv_len = strlen( value ); - slapi_entry_attr_replace( e, type, bvals ); + + if (value) { + bvals[0] = &bv; + bvals[1] = NULL; + bv.bv_val = (char*)value; + bv.bv_len = strlen( value ); + slapi_entry_attr_replace( e, type, bvals ); + } else { + slapi_entry_attr_delete( e, type ); + } } void diff --git a/ldap/servers/slapd/fedse.c b/ldap/servers/slapd/fedse.c index 2b30760f..f636a530 100644 --- a/ldap/servers/slapd/fedse.c +++ b/ldap/servers/slapd/fedse.c @@ -1841,8 +1841,7 @@ int fedse_create_startOK(char *filename, char *startokfilename, const char *con int rc = -1; if (configdir!=NULL) { - realconfigdir = slapi_ch_malloc(strlen(configdir)+1); - strcpy(realconfigdir, configdir); + realconfigdir = slapi_ch_strdup(configdir); } else if (id!=NULL) { realconfigdir = slapi_ch_smprintf("%s/%s", id, config_sub_dir); } diff --git a/ldap/servers/slapd/localhost.c b/ldap/servers/slapd/localhost.c index 0a367ad7..be04e2b0 100644 --- a/ldap/servers/slapd/localhost.c +++ b/ldap/servers/slapd/localhost.c @@ -130,11 +130,11 @@ find_localhost_DNS() if (domain == NULL) { return NULL; } - strcpy (hostname, hp->h_name); + PL_strncpyz (hostname, hp->h_name, sizeof(hostname)); if (domain[0] == '.') ++domain; if (domain[0]) { - strcat (hostname, "."); - strcat (hostname, domain); + PL_strcatn (hostname, sizeof(hostname), "."); + PL_strcatn (hostname, sizeof(hostname), domain); } LDAPDebug (LDAP_DEBUG_CONFIG, "hostname == %s\n", hostname, 0, 0); return slapi_ch_strdup (hostname); diff --git a/ldap/servers/slapd/mapping_tree.c b/ldap/servers/slapd/mapping_tree.c index a25f0ab3..eb1ffa78 100644 --- a/ldap/servers/slapd/mapping_tree.c +++ b/ldap/servers/slapd/mapping_tree.c @@ -3410,7 +3410,7 @@ static void dump_mapping_tree(mapping_tree_node *parent, int depth) } dump_indent[0] = '\0'; for (i = 0; i < depth; i++) - strcat(dump_indent, " "); + PL_strcatn(dump_indent, sizeof(dump_indent), " "); for (current = parent->mtn_children; current; current = current->mtn_brother) { diff --git a/ldap/servers/slapd/modutil.c b/ldap/servers/slapd/modutil.c index 94f4b30e..52b2a818 100644 --- a/ldap/servers/slapd/modutil.c +++ b/ldap/servers/slapd/modutil.c @@ -288,6 +288,7 @@ slapi_mods_add( Slapi_Mods *smods, int modtype, const char *type, unsigned long void slapi_mods_add_string( Slapi_Mods *smods, int modtype, const char *type, const char *val) { + PR_ASSERT(val); slapi_mods_add( smods, modtype, type, strlen(val), val); } diff --git a/ldap/servers/slapd/ntuserpin.c b/ldap/servers/slapd/ntuserpin.c index 2d3a9081..251e4bfd 100644 --- a/ldap/servers/slapd/ntuserpin.c +++ b/ldap/servers/slapd/ntuserpin.c @@ -121,8 +121,7 @@ static char *getPin(SVRCOREPinObj *obj, const char *tokenName, PRBool retry) buf[i].TokenLength)==0) { memset(pin, '\0', MAX_PASSWORD); - strncpy (pin, buf[i].Password, - buf[i].PasswordLength); + PL_strncpyz (pin, buf[i].Password, sizeof(pin)); slapi_ch_free ((void **) &buf); return slapi_ch_strdup(pin); } @@ -142,10 +141,10 @@ static char *getPin(SVRCOREPinObj *obj, const char *tokenName, PRBool retry) { slapi_ch_free ((void **) &buf); buf = (PK11_PIN *)slapi_ch_malloc(sizeof(PK11_PIN)); - strcpy (buf[0].TokenName, tokenName); - buf[0].TokenLength=strlen(tokenName); - strcpy (buf[0].Password, password); - buf[0].PasswordLength=strlen(password); + PL_strncpyz (buf[0].TokenName, tokenName, sizeof(buf[0].TokenName)); + buf[0].TokenLength=strlen(buf[0].TokenName); + PL_strncpyz (buf[0].Password, password, sizeof(buf[0].Password)); + buf[0].PasswordLength=strlen(buf[0].Password); if (i== cbRemotePassword) { /* Add a new token and password to the end of the table.*/ diff --git a/ldap/servers/slapd/ntwdog/ntwatchdog.c b/ldap/servers/slapd/ntwdog/ntwatchdog.c index 0c516827..5914f4e1 100644 --- a/ldap/servers/slapd/ntwdog/ntwatchdog.c +++ b/ldap/servers/slapd/ntwdog/ntwatchdog.c @@ -109,8 +109,9 @@ BOOL WD_GetServerConfig(char *szServerId, char *szServerRoot, LPDWORD cbServerRo return(bReturn); // query registry key to figure out config directory - sprintf(szSlapdKey, "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT, + snprintf(szSlapdKey, sizeof(szSlapdKey), "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT, szServerId); + szSlapdKey[sizeof(szSlapdKey)-1] = (char)0; dwResult = RegOpenKey(HKEY_LOCAL_MACHINE, szSlapdKey, &hSlapdKey); if(dwResult == ERROR_SUCCESS) @@ -139,7 +140,8 @@ BOOL WD_GetServerId(IN DWORD dwSubKey, OUT char *szServerId, IN OUT LPDWORD cbSe char szSlapdKey[MAX_LINE]; if(dwSubKey == 0) { - sprintf(szSlapdKey, "%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT); + snprintf(szSlapdKey, sizeof(szSlapdKey), "%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT); + szSlapdKey[sizeof(szSlapdKey)-1] = (char)0; dwResult = RegOpenKey(HKEY_LOCAL_MACHINE, szSlapdKey, &hSlapdKey); } @@ -236,8 +238,9 @@ DWORD WD_GetDefaultKeyValue(char *szServerName, char *szKeyName, DWORD dwDefault DWORD cbValue = sizeof(dwValue); // query registry key to figure out config directory - sprintf(szSlapdKey, "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT, + snprintf(szSlapdKey, sizeof(szSlapdKey), "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT, szServerName); + szSlapdKey[sizeof(szSlapdKey)-1] = (char)0; if(RegOpenKey(HKEY_LOCAL_MACHINE, szSlapdKey, &hSlapdKey) == ERROR_SUCCESS) { RegQueryValueEx(hSlapdKey, szKeyName, NULL, &dwValueType, @@ -360,7 +363,8 @@ BOOL WD_GetServerRoot(char *szServerRoot, char *szServerConfig) BOOL bReturn = FALSE; char *szChar = NULL; - strcpy(szTemp, szServerConfig); + strncpy(szTemp, szServerConfig, sizeof(szTemp)); + szTemp[sizeof(szTemp)-1] = (char)0; // szTemp should be something like c:\navgold\server\slapd-kennedy\config if(szChar = strrchr(szTemp,'\\')) { @@ -370,7 +374,8 @@ BOOL WD_GetServerRoot(char *szServerRoot, char *szServerConfig) { *szChar = 0; // szTemp should be c:\navgold\server - strcpy( szServerRoot, szTemp ); + strncpy( szServerRoot, szTemp, sizeof(gszServerRoot) ); + szServerRoot[sizeof(gszServerRoot)-1] = (char)0; wsprintf(szServerRootEnvVar, "%s=%s", SLAPD_ROOT, szTemp); putenv(szServerRootEnvVar); bReturn = TRUE; @@ -395,8 +400,9 @@ BOOL WD_GetConfigFromRegistry(char *szServerConfig, char *szServerName) DWORD dwResult = 0; // query registry key to figure out config directory - sprintf(szSlapdKey, "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT, + snprintf(szSlapdKey, sizeof(szSlapdKey), "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT, szServerName); + szSlapdKey[sizeof(szSlapdKey)-1] = (char)0; dwResult = RegOpenKey(HKEY_LOCAL_MACHINE, szSlapdKey, &hSlapdKey); if(dwResult != ERROR_SUCCESS) @@ -413,7 +419,8 @@ BOOL WD_GetConfigFromRegistry(char *szServerConfig, char *szServerName) } else { - strcpy(szServerConfig, szValueString); + strncpy(szServerConfig, szValueString, sizeof(gszServerConfig)); + szServerConfig[sizeof(gszServerConfig)-1] = (char)0; WD_UnixToDosPath(szServerConfig); WD_GetServerRoot(gszServerRoot, szServerConfig); bReturn = TRUE; @@ -437,7 +444,8 @@ BOOL WD_GetConfigFromCmdline(char *szServerConfig, char *szServerName, char *szC return(bReturn); } - strcpy(szServerConfig, szCmdLine); + strncpy(szServerConfig, szCmdLine, sizeof(gszServerConfig)); + szServerConfig[sizeof(gszServerConfig)-1] = (char)0; WD_UnixToDosPath(szCmdLine); WD_GetServerRoot(gszServerRoot, szCmdLine); @@ -450,7 +458,8 @@ BOOL WD_GetConfigFromCmdline(char *szServerConfig, char *szServerName, char *szC { szChar++; // szChar should point to slapd-kennedy - strcpy(szServerName, szChar); + strncpy(szServerName, szChar, sizeof(gszServerName)); + szServerName[sizeof(gszServerName)-1] = (char)0; WD_GetConfigFromRegistry(szServerConfig, szServerName); bReturn = TRUE; @@ -459,7 +468,8 @@ BOOL WD_GetConfigFromCmdline(char *szServerConfig, char *szServerName, char *szC else { // szCmdLine should be something like slapd-kennedy - strcpy(szServerName, szCmdLine); + strncpy(szServerName, szCmdLine, sizeof(gszServerName)); + szServerName[sizeof(gszServerName)-1] = (char)0; bReturn = WD_GetConfigFromRegistry(szServerConfig, szServerName); } @@ -486,7 +496,8 @@ BOOL WD_IsServerSecure(void) char *szTemp; FILE *fh = NULL; - sprintf(szFileName, "%s\\%s", gszServerConfig, SLAPD_CONF); + snprintf(szFileName, sizeof(szFileName), "%s\\%s", gszServerConfig, SLAPD_CONF); + szFileName[sizeof(szFileName)-1] = (char)0; if(fh = fopen(szFileName, "r")) { while(!feof(fh)) @@ -542,7 +553,8 @@ LONG APIENTRY WD_MainWndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam) char szShutdownEvent[MAX_LINE]; // shutdown web server, it should exit with 0, WatchDog won't restart it - sprintf(szShutdownEvent, "NS_%s", gszServerName); + snprintf(szShutdownEvent, sizeof(szShutdownEvent), "NS_%s", gszServerName); + szShutdownEvent[sizeof(szShutdownEvent)-1] = (char)0; hevShutdown = OpenEvent(EVENT_MODIFY_STATE, FALSE, szShutdownEvent); if(hevShutdown) { @@ -709,7 +721,8 @@ BOOL WD_StartServer(PROCESS_INFORMATION *pi) return(FALSE); } - strcpy(szServerPath, gszServerConfig); + strncpy(szServerPath, gszServerConfig, sizeof(szServerPath)); + szServerPath[sizeof(szServerPath)-1] = (char)0; WD_UnixToDosPath(szServerPath); // szServerPath should now be something similar to @@ -717,7 +730,8 @@ BOOL WD_StartServer(PROCESS_INFORMATION *pi) if(szChar = strrchr(szServerPath, '\\')) { *szChar = 0; - strcpy (szInstancePath, szServerPath); + strncpy (szInstancePath, szServerPath, sizeof(szInstancePath)); + szInstancePath[sizeof(szInstancePath)-1] = (char)0; if(szChar = strrchr(szServerPath, '\\')) { *szChar = 0; @@ -726,8 +740,9 @@ BOOL WD_StartServer(PROCESS_INFORMATION *pi) // For Directory Server, service-name is defined as slapd.exe, // in ldapserver/include/nt/regpargms.h - sprintf( szCmdLine, "%s\\bin\\%s\\server\\%s -D \"%s\"", szServerPath, + snprintf( szCmdLine, sizeof(szCmdLine), "%s\\bin\\%s\\server\\%s -D \"%s\"", szServerPath, PRODUCT_NAME, SERVICE_EXE, szInstancePath ); + szCmdLine[sizeof(szCmdLine)-1] = (char)0; // szCmdLine ex: c:\navgold\server\bin\slapd\slapd.exe // -f c:\navgold\server\slapd-kennedy\config @@ -877,29 +892,6 @@ BOOL WD_CreateCronThread(HANDLE hevWatchDogExit) //--------------------------------------------------------------------------// -// signals event create by SNMP agent for notification of server shutdown // -//--------------------------------------------------------------------------// -#if 0 -BOOL WS_SendSNMPTrapSignal(void) -{ - BOOL bReturn = FALSE; - HANDLE hevShutdown = NULL; - char szShutdownEvent[MAX_LINE]; - - sprintf(szShutdownEvent, NSEV_SNMPTRAP_HTTP); - hevShutdown = OpenEvent(EVENT_MODIFY_STATE, FALSE, szShutdownEvent); - if(hevShutdown) - { - SetEvent(hevShutdown); - CLOSEHANDLE(hevShutdown); - bReturn = TRUE; - } - return(bReturn); -} -#endif - - -//--------------------------------------------------------------------------// // // //--------------------------------------------------------------------------// BOOL WD_MonitorServer(void) @@ -932,7 +924,8 @@ BOOL WD_MonitorServer(void) // shutdown web server //CLOSEHANDLE(pi.hProcess); // XXXahakim close them after TerminateProcess() //CLOSEHANDLE(pi.hThread); - sprintf(szServerDoneEvent, "NS_%s", gszServerName); + snprintf(szServerDoneEvent, sizeof(szServerDoneEvent), "NS_%s", gszServerName); + szServerDoneEvent[sizeof(szServerDoneEvent)-1] = (char)0; hevServerDone = OpenEvent(EVENT_MODIFY_STATE, FALSE, szServerDoneEvent); if(hevServerDone) { @@ -1079,7 +1072,8 @@ VOID WD_ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) bOkToProceed = (gsshServiceStatus != (SERVICE_STATUS_HANDLE)NULL); if(bOkToProceed) { - strcpy(gszServerName, lpszArgv[0]); + strncpy(gszServerName, lpszArgv[0], sizeof(gszServerName)); + gszServerName[sizeof(gszServerName)-1] = (char)0; bOkToProceed = WD_GetConfigFromRegistry(gszServerConfig, gszServerName); } diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c index 7ff8ff06..99010e8c 100644 --- a/ldap/servers/slapd/opshared.c +++ b/ldap/servers/slapd/opshared.c @@ -196,6 +196,7 @@ op_shared_search (Slapi_PBlock *pb, int send_result) #define SLAPD_SEARCH_FMTSTR_BASE_INT "conn=%s op=%d SRCH base=\"%s\" scope=%d " #define SLAPD_SEARCH_FMTSTR_REMAINDER " attrs=%s%s\n" + PR_ASSERT(fstr); if ( strlen(fstr) > 1024 ) { /* diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c index 38dc7f44..42ded667 100644 --- a/ldap/servers/slapd/plugin.c +++ b/ldap/servers/slapd/plugin.c @@ -1775,27 +1775,6 @@ set_plugin_config_from_entry( return status; } -#if 0 -static PRBool -plugin_matches_key (char *arg, char *key) -{ - PRBool haveVal = strlen (arg) > strlen (key); - return (haveVal && strncasecmp (arg, key, strlen (key)) == 0); -} - -static char* -plugin_get_str_val (char *arg, char *key) -{ - return &(arg[strlen (key)]); -} - -static PRBool -plugin_get_bool_val (char*arg, char *key, char *true_val) -{ - return (strcasecmp (&(arg[strlen (key)]), true_val) == 0); -} -#endif - /* This function is called after the plugin init function has been called which fills in the desc part of the plugin */ diff --git a/ldap/servers/slapd/protect_db.c b/ldap/servers/slapd/protect_db.c index 4efe729a..4d7183ad 100644 --- a/ldap/servers/slapd/protect_db.c +++ b/ldap/servers/slapd/protect_db.c @@ -55,7 +55,8 @@ grab_lockfile() gets called by an atexit function, and NSPR is long gone by then. */ /* Get the name of the lockfile */ - sprintf(lockfile, "%s/%s", slapdFrontendConfig->instancedir, LOCK_FILE); + snprintf(lockfile, sizeof(lockfile), "%s/%s", slapdFrontendConfig->instancedir, LOCK_FILE); + lockfile[sizeof(lockfile)-1] = (char)0; /* Get our pid */ pid = getpid(); @@ -125,7 +126,8 @@ release_lockfile() /* This function assumes that the caller owns the lock, it doesn't check to make sure! */ - sprintf(lockfile, "%s/%s", slapdFrontendConfig->instancedir, LOCK_FILE); + snprintf(lockfile, sizeof(lockfile), "%s/%s", slapdFrontendConfig->instancedir, LOCK_FILE); + lockfile[sizeof(lockfile)-1] = (char)0; unlink(lockfile); } @@ -191,7 +193,8 @@ add_this_process_to(char *dir_name) PRFileDesc* prfd; slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig(); - sprintf(file_name, "%s/%d", dir_name, getpid()); + snprintf(file_name, sizeof(file_name), "%s/%d", dir_name, getpid()); + file_name[sizeof(file_name)-1] = (char)0; if ((prfd = PR_Open(file_name, PR_RDWR | PR_CREATE_FILE, 0666)) == NULL) { LDAPDebug(LDAP_DEBUG_ANY, FILE_CREATE_WARNING, file_name, 0, 0); @@ -317,10 +320,14 @@ remove_slapd_process() /* Create the name of the directories that hold the pids of the currently running * ns-slapd processes */ - sprintf(lock_dir, "%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR); - sprintf(import_dir, "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, IMPORT_DIR); - sprintf(export_dir, "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, EXPORT_DIR); - sprintf(server_dir, "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, SERVER_DIR); + snprintf(lock_dir, sizeof(lock_dir), "%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR); + lock_dir[sizeof(lock_dir)-1] = (char)0; + snprintf(import_dir, sizeof(import_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, IMPORT_DIR); + import_dir[sizeof(import_dir)-1] = (char)0; + snprintf(export_dir, sizeof(export_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, EXPORT_DIR); + export_dir[sizeof(export_dir)-1] = (char)0; + snprintf(server_dir, sizeof(server_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, SERVER_DIR); + server_dir[sizeof(server_dir)-1] = (char)0; /* Grab the lockfile */ if (grab_lockfile() != 0) { @@ -353,10 +360,14 @@ add_new_slapd_process(int exec_mode, int r_flag, int skip_flag) /* Create the name of the directories that hold the pids of the currently running * ns-slapd processes */ - sprintf(lock_dir, "%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR); - sprintf(import_dir, "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, IMPORT_DIR); - sprintf(export_dir, "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, EXPORT_DIR); - sprintf(server_dir, "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, SERVER_DIR); + snprintf(lock_dir, sizeof(lock_dir), "%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR); + lock_dir[sizeof(lock_dir)-1] = (char)0; + snprintf(import_dir, sizeof(import_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, IMPORT_DIR); + import_dir[sizeof(import_dir)-1] = (char)0; + snprintf(export_dir, sizeof(export_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, EXPORT_DIR); + export_dir[sizeof(export_dir)-1] = (char)0; + snprintf(server_dir, sizeof(server_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, SERVER_DIR); + server_dir[sizeof(server_dir)-1] = (char)0; /* Grab the lockfile */ if (grab_lockfile() != 0) { @@ -491,8 +502,10 @@ is_slapd_running() { slapdFrontendConfig_t *cfg = getFrontendConfig(); int running = 0; - sprintf(lock_dir, "%s/%s", cfg->instancedir, LOCK_DIR); - sprintf( server_dir, "%s/%s/%s", cfg->instancedir, LOCK_DIR, SERVER_DIR); + snprintf(lock_dir, sizeof(lock_dir), "%s/%s", cfg->instancedir, LOCK_DIR); + lock_dir[sizeof(lock_dir)-1] = (char)0; + snprintf( server_dir, sizeof(server_dir), "%s/%s/%s", cfg->instancedir, LOCK_DIR, SERVER_DIR); + server_dir[sizeof(server_dir)-1] = (char)0; /* Grab the lockfile */ if (grab_lockfile() != 0) { @@ -620,14 +633,14 @@ add_new_slapd_process(int exec_mode, int r_flag, int skip_flag) } /* Create the names for the mutexes */ - strcpy(mutexName, slapdFrontendConfig->instancedir); + PL_strncpyz(mutexName, slapdFrontendConfig->instancedir, sizeof(mutexName)); /* Make sure the name of the mutex is legal. */ fix_mutex_name(mutexName); - sprintf(serverMutexName, "%s/server", mutexName); - sprintf(importMutexName, "%s/import", mutexName); - sprintf(exportMutexName, "%s/export", mutexName); + PR_snprintf(serverMutexName, sizeof(serverMutexName), "%s/server", mutexName); + PR_snprintf(importMutexName, sizeof(importMutexName), "%s/import", mutexName); + PR_snprintf(exportMutexName, sizeof(exportMutexName), "%s/export", mutexName); /* Fill in the security crap for the mutex */ pSD = (PSECURITY_DESCRIPTOR)slapi_ch_malloc( sizeof( SECURITY_DESCRIPTOR ) ); diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h index 7ad6ee4d..687aa727 100644 --- a/ldap/servers/slapd/proto-slap.h +++ b/ldap/servers/slapd/proto-slap.h @@ -676,9 +676,6 @@ struct slapi_componentid * pw_get_componentID(); * referral.c */ void referrals_free (); -Ref_Array * ref_array_dup(); -void ref_array_dup_free(Ref_Array *the_copy); -void update_global_referrals( Slapi_PBlock *pb ); struct berval **ref_adjust( Slapi_PBlock *pb, struct berval **urls, const Slapi_DN *refcontainerdn, int is_reference ); /* GGOODREPL temporarily in slapi-plugin.h struct berval **get_data_source( char *dn, int orc, Ref_Array * ); */ diff --git a/ldap/servers/slapd/referral.c b/ldap/servers/slapd/referral.c index cede05d6..429f6ef4 100644 --- a/ldap/servers/slapd/referral.c +++ b/ldap/servers/slapd/referral.c @@ -12,36 +12,12 @@ #include "slap.h" /* Forward Decls */ -static int ref_array_del(Ref **target, int write, int read); -static int ref_array_add(const char *dn, struct berval *referral, int write, int read); -static Ref **ref_array_find(const char *dn); -static int ref_array_mod(Ref **target, struct berval *referral, int write, int read); -static void strcat_escaped( char *s1, char *s2 ); static void adjust_referral_basedn( char **urlp, const Slapi_DN *refcontainerdn, char *opdn_norm, int isreference ); static int dn_is_below( const char *dn_norm, const char *ancestor_norm ); static Ref_Array *g_get_global_referrals(void); static void ref_free (Ref **goner); static Ref_Array global_referrals; -struct refCb { - int type; - char *cbName; - void (*cb)(Slapi_PBlock *, void *); - void *cbData; - struct refCb *next; -}; - -struct refCb *refCbList=NULL; - -int -ref_register_callback(int type, char *description, - void (*cb)(Slapi_PBlock *, void *), void *cbData); -int -ref_remove_callback(char *description); -static -int ref_call_cbs(int type, Slapi_PBlock *pb); - - #define SLAPD_DEFAULT_REFARRAY_SIZE 10 /* @@ -76,438 +52,6 @@ g_get_global_referrals(void) return( &global_referrals ); } -/* - * Function: ref_array_del - * - * Returns: 0 good, -1 bad. - * - * Description: finds "dn" in the list and unsets the read or write - * flag(s). If both are then zero, then it frees up that entry. - * target should point to the referral that is to be deleted. - * Note: This does NOT lock global_referrals.ra_rwlock. - * - * Author: RJP - */ -static int -ref_array_del(Ref **target, int write, int read) -{ - Ref **lastref = NULL; - Ref_Array *grefs = NULL; - - grefs = g_get_global_referrals(); - - if (target == NULL) { - return(-1); - } - - /*Unset either or both flags*/ - if (write) { - (*target)->ref_writes = 0; - } - if (read) { - (*target)->ref_reads = 0; - grefs->ra_readcount--; - } - - /*If there is a flag set, then don't delete the referral*/ - if (((*target)->ref_writes == 1) || (*target)->ref_reads == 1){ - return(0); - } - - /* Free up target */ - ref_free(target); - - - /* - * Okay, we want to maintain our array's compactedness, - * so we take the referral that's in the last position, and - * put that in target's place. If they are one and the - * same, then no problem. This shouldn't ever seg fault. - * (famous last words). - */ - lastref = &grefs->ra_refs[grefs->ra_nextindex - 1]; - - *target = *lastref; - - grefs->ra_refs[grefs->ra_nextindex - 1] = NULL; - - /*reset the next_index*/ - grefs->ra_nextindex--; - - return(0); - -} - - -/* - * Function: ref_array_replace - * - * Returns: 0 good, -1 bad. - * - * Description: Locks the mutex associated with global_referrals, - * adds that referral and "dn" to the global_referrals if it - * doesn't exist already. If it does exist, and the new - * referral is different, then the old one gets clobbered. - * If referral is NULL, then it deletes the referral - * associated with dn. - * Note: This locks global_referrals.ra_rwlock. - * - * Author: RJP - */ -int -ref_array_replace(const char *dn, struct berval *referral, int write, int read) -{ - Ref **target = NULL; - int err; - Ref_Array *grefs = NULL; - - grefs = g_get_global_referrals(); - - if (dn == NULL) { - return(0); - } - - GR_LOCK_WRITE(); - - /* Find the referral, if any. */ - target = ref_array_find(dn); - - /* If datasource is NULL, then delete target. */ - if ( referral == NULL ){ - - /* If target is null, then there is nothing to do. */ - if (target == NULL) { - GR_UNLOCK_WRITE(); - return(0); - } - err = ref_array_del(target, write, read); - - GR_UNLOCK_WRITE(); - - return(err); - } - - /* If target is NULL, then add target to the end. */ - if ( target == NULL) { - err = ref_array_add(dn, referral, write, read); - GR_UNLOCK_WRITE(); - return(err); - } - - /* Else, the referral already exists and we should modify it. */ - err = ref_array_mod(target, referral, write, read); - GR_UNLOCK_WRITE(); - return(err); -} - - -/* - * Function: ref_array_mod - * - * Returns: 0 good, -1 bad. - * - * Description: modifies the existing referral. - * First it checks the host:port in datasource - * against the host:port in the existing referral. - * If they don't match, then it replaces the referral - * - * Note: This does NOT lock global_referrals.ra_rwlock. - * - * Author: RJP - */ -static int -ref_array_mod(Ref **target, struct berval *referral, int write, int read) -{ - Ref_Array *grefs = NULL; - - grefs = g_get_global_referrals(); - - if (referral == NULL || target == NULL) { - return(0); - } - - /* Actually, instead of comparing them, we might as well just swap */ - ber_bvfree( (*target)->ref_referral ); - - (*target)->ref_referral = referral ; - - /* - * We have to update the read/write flags which - * refer reads and writes, respectively - */ - if (write) { - (*target)->ref_writes = 1; - } - if (read) { - /*Don't update the readcount unnecessarily*/ - if ((*target)->ref_reads == 0) { - grefs->ra_readcount++; - } - - (*target)->ref_reads = 1; - } - - return(0); - -} - - - -/* - * Function: ref_array_add - * - * Returns: 0 good, -1 bad. - * - * Description: adds that referral and "dn" to the global_referrals - * Note: This does NOT lock global_referrals.ra_rwlock. - * - * Author: RJP - */ -static int -ref_array_add(const char *dn, struct berval *referral, int write, int read) -{ - Ref **target = NULL; - Ref_Array *grefs = NULL; - - grefs = g_get_global_referrals(); - - if (dn == NULL || referral == NULL) { - return(0); - } - - - /* We may have to realloc if we are about to index an out-of-range slot */ - if (grefs->ra_nextindex >= grefs->ra_size){ - /* reset the size */ - grefs->ra_size += 10; - - /* reallocate */ - grefs->ra_refs = (Ref **) slapi_ch_realloc((char *) grefs->ra_refs, - grefs->ra_size * (sizeof(Ref *))); - } - - /* Tack the new referral to the end. */ - target = &(grefs->ra_refs[grefs->ra_nextindex]); - - /* Malloc and fill the fields of the new referral */ - (*target) = (Ref *) slapi_ch_malloc( sizeof(Ref)); - (*target)->ref_dn = slapi_dn_normalize_case(slapi_ch_strdup(dn)); - (*target)->ref_referral = referral; - - /* Update the next available index */ - grefs->ra_nextindex++; - - (*target)->ref_writes = 0; - (*target)->ref_reads = 0; - - /* - * We have to update the read/write flags which - * refer reads and writes, respectively - */ - if (write) { - (*target)->ref_writes = 1; - } - if (read) { - (*target)->ref_reads = 1; - grefs->ra_readcount++; - } - - return(0); -} - -/* - * Function: ref_array_find - * - * Returns: a pointer to a pointer to a Ref, or NULL - * - * Description: Traverses the array of referrals, until - * it either finds a match or gets to the end. - * Note: This DOES NOT lock global_referrals.ra_rwlock. - * - * Author: RJP - * - */ -static Ref ** -ref_array_find(const char *dn) -{ - int walker; - Ref_Array *grefs = NULL; - - grefs = g_get_global_referrals(); - - if (dn == NULL) { - return(NULL); - } - - /* Walk down the array, testing for a match */ - for (walker = 0; walker < grefs->ra_nextindex; walker++){ - - if (strcasecmp (grefs->ra_refs[walker]->ref_dn, dn) == 0) { - return(&grefs->ra_refs[walker]); - } - } - return(NULL); -} - -/* - * Function: send_read_referrals - * - * Returns: A copy of global_referrals - * - * Description: Given a dn, this function sends all the copyingfrom - * referrals beneath "dn" that are within "scope." - * returns a copy of the global_referrals array - * that it makes for use later. This is to avoid - * any race conditions of ORC ending in the middle - * of the search and scewing things up. NULL is returned - * if there are no copyingfrom referrals in there. - * - * If "dn" does not exactly match a referral's dn, we append - * "/referralDN" to the referral itself, i.e, we send a - * referral like this: - * ldap://host:port/dn - * instead of one like this: - * ldap://host:port - * We do not append the referral DN to the referrals present - * in the copy of the global_referrals array that we return. - * - * Author: RJP - * - */ -Ref_Array * -send_read_referrals(Slapi_PBlock *pb, int scope, char *dn, - struct berval ***urls) -{ - int walker, urllen, dnlen; - struct berval *refs[2], refcopy; - char *urlcopy; - Ref_Array *grefs = NULL; - Ref_Array *the_copy = NULL; - int found_one = 0; - - /* Get a pointer to global_referrals */ - grefs = g_get_global_referrals(); - - GR_LOCK_READ(); - - /*If no copyingfroms, just return*/ - if (grefs->ra_readcount <= 0) { - GR_UNLOCK_READ(); - return(NULL); - } - - refs[1] = NULL; - - /* - * Walk through the refs in the_copy and send any referrals - * that are below "dn". Take "scope" into account as well. - */ - for (walker = 0; walker < grefs->ra_nextindex; walker++) { - if ( grefs->ra_refs[walker]->ref_reads && - (( scope == LDAP_SCOPE_BASE && - strcasecmp(grefs->ra_refs[walker]->ref_dn, dn) == 0 ) || - ( scope == LDAP_SCOPE_ONELEVEL && - slapi_dn_isparent(dn, grefs->ra_refs[walker]->ref_dn)) || - ( scope == LDAP_SCOPE_SUBTREE && - slapi_dn_issuffix(grefs->ra_refs[walker]->ref_dn, dn)))) { - found_one = 1; - - /* - * Make an array of 1 referral. If the referral DN is below "dn", - * i.e, it is not the same as "dn", we make a copy and append a - * URL-escaped version of the referral DN to the original referral. - */ - if ( scope == LDAP_SCOPE_BASE || - strcasecmp( grefs->ra_refs[walker]->ref_dn, dn ) == 0 ) { - refs[0] = grefs->ra_refs[walker]->ref_referral; - urlcopy = NULL; - } else { - urllen = strlen( grefs->ra_refs[walker]->ref_referral->bv_val ); - dnlen = strlen( grefs->ra_refs[walker]->ref_dn ); - /* space for worst-case expansion due to escape plus room for '/' */ - urlcopy = slapi_ch_malloc( urllen + 3 * dnlen + 2 ); - - strcpy( urlcopy, grefs->ra_refs[walker]->ref_referral->bv_val ); - urlcopy[urllen] = '/'; - ++urllen; - urlcopy[urllen] = '\0'; - strcat_escaped( urlcopy + urllen, grefs->ra_refs[walker]->ref_dn ); - - refcopy.bv_val = urlcopy; - refcopy.bv_len = strlen( urlcopy ); - refs[0] = &refcopy; - } - - send_ldap_referral( pb, NULL, refs, urls ); - slapi_pblock_set( pb, SLAPI_SEARCH_REFERRALS, *urls ); - - if ( urlcopy != NULL ) { - slapi_ch_free( (void **)&urlcopy ); - } - } - } - - /* Make a copy of global_referrals to avoid any race conditions */ - if (found_one) { - the_copy = ref_array_dup(); - } - - GR_UNLOCK_READ(); - - /* - * After we sent all the referrals, return the copy of - * global_referrals for use later. If there were none found, return - * NULL - */ - return(the_copy); -} - -/* - * Function: ref_array_dup - * - * Returns: a copy of global_referrals - * - * Description: Makes a copy of global_referrals and returns that puppy - * Note: Does not lock global_referrals. - * - * Author: RJP - * - */ -Ref_Array * -ref_array_dup(void) -{ - Ref_Array *grefs = NULL; - Ref_Array *the_copy = NULL; - int walker; - - /*Allocate the first structure*/ - the_copy = (Ref_Array *) slapi_ch_calloc(1, sizeof(Ref_Array)); - - /* Don't bother with the lock, it's only a local copy. */ - the_copy->ra_rwlock = NULL; - - /*Grab a reference to the global_referrals*/ - grefs = g_get_global_referrals(); - - /* Initialize all the fields of the copy. */ - the_copy->ra_size = grefs->ra_size; - the_copy->ra_nextindex = grefs->ra_nextindex; - the_copy->ra_readcount = grefs->ra_readcount; - the_copy->ra_refs = (Ref **) slapi_ch_calloc(the_copy->ra_size, sizeof( Ref * )); - - /*Walk down grefs, copying each Ref struct */ - for (walker = 0; walker < grefs->ra_nextindex; walker++) { - the_copy->ra_refs[walker] = (Ref *)slapi_ch_calloc(1, sizeof(Ref)); - the_copy->ra_refs[walker]->ref_dn = slapi_ch_strdup(grefs->ra_refs[walker]->ref_dn); - the_copy->ra_refs[walker]->ref_referral = slapi_ch_bvdup(grefs->ra_refs[walker]->ref_referral); - the_copy->ra_refs[walker]->ref_reads = grefs->ra_refs[walker]->ref_reads; - the_copy->ra_refs[walker]->ref_writes = grefs->ra_refs[walker]->ref_writes; - } - - return(the_copy); - -} - /* * Function: ref_free @@ -527,39 +71,6 @@ ref_free (Ref **goner) slapi_ch_free((void**) goner); } -/* - * Function: ref_array_dup_free - * - * Returns: nothingness - * - * Description: takes a Ref_Array dup and frees that puppy - * - * Author: RJP - * - */ -void -ref_array_dup_free(Ref_Array *the_copy) -{ - int walker; - - if (the_copy == NULL) { - return; - } - - /* Walk down the array, deleting each referral */ - for (walker = 0; walker < the_copy->ra_nextindex; walker++) - { - ref_free (&the_copy->ra_refs[walker]); - } - - /* free the array of pointers */ - slapi_ch_free((void **) &the_copy->ra_refs); - slapi_ch_free((void **) &the_copy); - - return; -} - - /* * Function: referrals_free @@ -595,125 +106,6 @@ referrals_free (void) } /* - * Function: ref_array_moddn - * - * Returns: 0 good, -1 bad. - * - * Description: modifies the existing referral's dn. - * First it locks global_referrals.ra_rwlock. - * Then it clobbers the existing dn. - * Then it replaces it with a new dn constructed - * from newrdn. - * Note: This locks global_referrals.ra_rwlock. - * - * Author: RJP - */ -void -ref_array_moddn(const char *dn, char *newrdn, Slapi_PBlock *pb) -{ - char *pdn = NULL; - char *newdn = NULL; - Ref **target = NULL; - Ref_Array *grefs = NULL; - - grefs = g_get_global_referrals(); - - if (dn == NULL) { - return; - } - - GR_LOCK_WRITE(); - - /* Find the referral. */ - target = ref_array_find(dn); - - /* - * If we can't find it, then we're done. This is okay, because this - * is the only check that is made to see if the entry has a - * copiedfrom in it. - */ - if (target == NULL) { - GR_UNLOCK_WRITE(); - return; - } - /* construct the new dn */ - if ( (pdn = slapi_dn_beparent( pb, dn )) != NULL ) { - /* parent + rdn + separator(s) + null */ - newdn = (char *) slapi_ch_malloc( strlen( pdn ) + strlen( newrdn ) + 3 ); - strcpy( newdn, newrdn ); - strcat( newdn, ", " ); - strcat( newdn, pdn ); - } else { - newdn = (char *) slapi_ch_strdup( newrdn ); - } - slapi_ch_free((void **) &pdn ); - (void) slapi_dn_normalize_case( newdn ); - - - /* We have found the referral. blow away the dn*/ - slapi_ch_free((void**) &((*target)->ref_dn)); - - /* stick in the new one. */ - (*target)->ref_dn = newdn; - - GR_UNLOCK_WRITE(); - - return; -} - - -/* - * HREF_CHAR_ACCEPTABLE was copied from libldap/tmplout.c - */ -/* Note: an identical function is in ../plugins/replication/replutil.c */ -#define HREF_CHAR_ACCEPTABLE( c ) (( c >= '-' && c <= '9' ) || \ - ( c >= '@' && c <= 'Z' ) || \ - ( c == '_' ) || \ - ( c >= 'a' && c <= 'z' )) - -/* - * Function: strcat_escaped - * - * Returns: nothing - * - * Description: Appends string s2 to s1, URL-escaping (%HH) unsafe - * characters in s2 as appropriate. This function was - * copied from libldap/tmplout.c. - * - * Author: MCS - */ -/* - * append s2 to s1, URL-escaping (%HH) unsafe characters - */ -/* Note: an identical function is in ../plugins/replication/replutil.c */ -static void -strcat_escaped( char *s1, char *s2 ) -{ - char *p, *q; - char *hexdig = "0123456789ABCDEF"; - - p = s1 + strlen( s1 ); - for ( q = s2; *q != '\0'; ++q ) { - if ( HREF_CHAR_ACCEPTABLE( *q )) { - *p++ = *q; - } else { - *p++ = '%'; - *p++ = hexdig[ 0x0F & ((*(unsigned char*)q) >> 4) ]; - *p++ = hexdig[ 0x0F & *q ]; - } - } - - *p = '\0'; -} - -void -update_global_referrals(Slapi_PBlock *pb) -{ - ref_call_cbs(0,pb); - return; -} - -/* * ref_adjust() -- adjust referrals based on operation-specific data. * The general idea is for us (the server) to be smart so LDAP clients * can be as dumb as possible. @@ -1124,80 +516,3 @@ get_data_source(Slapi_PBlock *pb, const Slapi_DN *sdn, int orc, void *cfrp) return(bvp); } - - -int -ref_register_callback(int type, char *description, - void (*cb)(Slapi_PBlock *, void *), void *cbData) -{ - struct refCb *cbPtr; - struct refCb *newCb; - - if(NULL == (newCb = - (struct refCb *)slapi_ch_calloc(1,sizeof(struct refCb)))) { - /* out of memory? */ - return(-1); - } - newCb->type = type; - newCb->next = NULL; - newCb->cb = cb; - newCb->cbData = cbData; - newCb->cbName = slapi_ch_strdup(description); - - if(NULL == refCbList) { - refCbList = newCb; - return(0); - } - cbPtr = refCbList; - while(NULL != cbPtr->next) cbPtr = cbPtr->next; - cbPtr->next=newCb; - - return(0); -} - -int -ref_remove_callback(char *description) -{ - struct refCb *cbPtr = refCbList; - struct refCb *cbPrev = refCbList; - - if((NULL == description) || (NULL == cbPtr)) - return(-1); - - while(cbPtr) { - if(!strcmp(description,cbPtr->cbName)) { - if(cbPrev == refCbList) { - refCbList = cbPtr->next; - } else { - cbPrev->next = cbPtr->next; - } - slapi_ch_free((void **)&cbPtr->cbName); - /* we don't know how the cbData was allocated...we won't attempt - to free it */ - slapi_ch_free((void **)&cbPtr); - break; - } - cbPrev = cbPtr; - cbPtr = cbPtr->next; - } - - return(0); -} - -static -int ref_call_cbs(int type, Slapi_PBlock *pb) -{ - struct refCb *cbPtr = refCbList; - - if(NULL == cbPtr) { - return(0); - } - - while(cbPtr) { - (*cbPtr->cb)(pb, cbPtr->cbData); - cbPtr = cbPtr->next; - } - - return(0); -} - diff --git a/ldap/servers/slapd/result.c b/ldap/servers/slapd/result.c index 9a406e85..003274b7 100644 --- a/ldap/servers/slapd/result.c +++ b/ldap/servers/slapd/result.c @@ -98,7 +98,7 @@ g_set_default_referral( struct berval **ldap_url ) { /* check to see if we want to delete all referrals */ if ( ldap_url && ldap_url[0] && - strcasecmp ( (char *)ldap_url[0]->bv_val, REFERRAL_REMOVE_CMD) == 0 ) { + PL_strncasecmp ( (char *)ldap_url[0]->bv_val, REFERRAL_REMOVE_CMD, ldap_url[0]->bv_len ) == 0 ) { delete_default_referral(slapdFrontendConfig->defaultreferral); slapdFrontendConfig->defaultreferral = NULL; return; diff --git a/ldap/servers/slapd/saslbind.c b/ldap/servers/slapd/saslbind.c index 1a6c2f14..c68b61a4 100644 --- a/ldap/servers/slapd/saslbind.c +++ b/ldap/servers/slapd/saslbind.c @@ -422,7 +422,7 @@ static int ids_sasl_canon_user( } /* TODO: canonicalize */ - strcpy(out_user, dn); + PL_strncpyz(out_user, dn, out_umax); #ifdef CYRUS_SASL /* the length of out_user needs to be set for Cyrus SASL */ *out_ulen = strlen(out_user); @@ -433,7 +433,7 @@ static int ids_sasl_canon_user( /* The authid can start with dn:. In such case remove it */ if (strncasecmp(authid,"dn:",3) == 0 ) offset = 3; - strcpy(out_authid, authid+offset); + PL_strncpyz(out_authid, authid+offset, out_amax); } *out_ulen = -1; *out_alen = -1; diff --git a/ldap/servers/slapd/schema.c b/ldap/servers/slapd/schema.c index 7162a968..632120c6 100644 --- a/ldap/servers/slapd/schema.c +++ b/ldap/servers/slapd/schema.c @@ -3183,6 +3183,11 @@ read_at_ldif(const char *input, struct asyntaxinfo **asipp, char *errorbuf, attr_names = parse_qdescrs(psbAttrName->buffer, &num_names); if ( NULL != attr_names ) { first_attr_name = attr_names[0]; + } else { /* NAME followed by nothing violates syntax */ + schema_create_errormsg( errorbuf, errorbufsize, schema_errprefix_at, + input, "Missing or invalid attribute name" ); + status = invalid_syntax_error; + goto done; } } @@ -3192,7 +3197,7 @@ read_at_ldif(const char *input, struct asyntaxinfo **asipp, char *errorbuf, * if the attribute ldif doesn't have an OID, we'll make the oid * attrname-oid */ - if ( strcasecmp ( pOid, "NAME" ) == 0 ) { + if ( (strcasecmp ( pOid, "NAME" ) == 0) && (first_attr_name)) { slapi_ch_free_string( &pOid ); pOid = slapi_ch_smprintf("%s-oid", first_attr_name ); } diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h index fc956615..05862cd6 100644 --- a/ldap/servers/slapd/slapi-private.h +++ b/ldap/servers/slapd/slapi-private.h @@ -585,19 +585,6 @@ typedef struct index_config int system; /* marks this index as system */ }IndexConfig; -int be_create_instance (const char *type, /* for now, must be "ldbm" */ - const char *name, /* gloably unique instance name */ - const char *root, /* backend root, i.e. o=mcom.com */ - int cache_size, /* cache size in bytes; 0 for default */ - IndexConfig *indexes, /* indexes in addition to standard */ - int index_count, /* number of elements in indexes */ - void *plugin_identity /* identity of the calling plugin */ - ); -int be_remove_instance (const char *type, /* for now, must be "ldbm" */ - const char *name, /* gloably unique instance name */ - void *plugin_identity /* identity of the calling plugin */ - ); - void be_set_sizelimit(Slapi_Backend * be, int sizelimit); void be_set_timelimit(Slapi_Backend * be, int timelimit); @@ -1123,14 +1110,8 @@ int config_get_secureport( void ); char* get_localhost_DN( void ); char* get_localhost_DNS( void ); -int ref_array_replace(const char *dn, struct berval *referral, int write, int read); -void ref_array_moddn(const char *dn, char *newrdn, Slapi_PBlock *pb); -int ref_register_callback(int type, char *description, - void (*cb)(Slapi_PBlock *, void *), void *cbData); -int ref_remove_callback(char *description); /* GGOODREPL get_data_source definition should move into repl DLL */ struct berval **get_data_source(Slapi_PBlock *pb, const Slapi_DN *sdn, int orc, void *cf_refs); -/* Ref_Array *send_read_referrals(Slapi_PBlock *pb, int scope, char *dn, struct berval ***urls); */ /* JCMREPL - IFP and CFP should be defined centrally */ #ifndef _IFP diff --git a/ldap/servers/slapd/ssl.c b/ldap/servers/slapd/ssl.c index 70ca82da..93a7ae94 100644 --- a/ldap/servers/slapd/ssl.c +++ b/ldap/servers/slapd/ssl.c @@ -379,7 +379,7 @@ slapd_nss_init(int init_ssl, int config_available) } instancedir = config_get_instancedir(); - strcpy(path, instancedir); + PL_strncpyz(path, instancedir, sizeof(path)); slapi_ch_free_string(&instancedir); /* make sure path does not end in the path separator character */ @@ -398,7 +398,7 @@ slapd_nss_init(int init_ssl, int config_available) if(keyfn && certfn) { if (is_abspath(certfn)) { /* first, initialize path from the certfn */ - strcpy(path, certfn); + PL_strncpyz(path, certfn, sizeof(path)); /* extract path from cert db filename */ val = strrchr(path, '/'); if (!val) { @@ -407,15 +407,15 @@ slapd_nss_init(int init_ssl, int config_available) *val = 0; /* path is initialized */ /* next, init the cert db prefix */ val++; - strcpy(certPref, val); + PL_strncpyz(certPref, val, sizeof(certPref)); } else { - strcpy(val, certfn); + PL_strncpyz(val, certfn, sizeof(path)-(val-path)); val = strrchr(path, '/'); if (!val) { val = strrchr(path, '\\'); } val++; - strcpy(certPref, val); + PL_strncpyz(certPref, val, sizeof(certPref)); *val = '\0'; } /* path represents now the base directory where cert, key, pin, and module db live */ @@ -437,7 +437,7 @@ slapd_nss_init(int init_ssl, int config_available) } else { val = keyfn; } - strcpy(keyPref, val); + PL_strncpyz(keyPref, val, sizeof(keyPref)); /* richm - use strrstr to get the last occurance of -key in the string, in case the instance is named slapd-key - the keydb name will be slapd-key-key3.db */ @@ -458,8 +458,8 @@ slapd_nss_init(int init_ssl, int config_available) (certfn ? "found" : "not found")); } PR_snprintf(certPref, sizeof(certPref), "%s-", val); - strcpy(keyPref, certPref); - strcpy(val, "alias/"); + PL_strncpyz(keyPref, certPref, sizeof(keyPref)); + PL_strncpyz(val, "alias/", sizeof(path)-(val-path)); } slapi_ch_free((void **) &certfn); @@ -661,7 +661,7 @@ slapd_ssl_init() { /* Step Three.5: Set SSL cipher preferences */ *cipher_string = 0; if(ciphers && (*ciphers) && strcmp(ciphers, "blank")) - strcpy(cipher_string, ciphers); + PL_strncpyz(cipher_string, ciphers, sizeof(cipher_string)); slapi_ch_free((void **) &ciphers); if( NULL != (val = _conf_setciphers(cipher_string)) ) { @@ -796,7 +796,7 @@ int slapd_ssl_init2(PRFileDesc **fd, int startTLS) if( token && personality ) { if( !strcasecmp(token, "internal") || !strcasecmp(token, "internal (software)") ) - strcpy(cert_name, personality); + PL_strncpyz(cert_name, personality, sizeof(cert_name)); else /* external PKCS #11 token - attach token name */ PR_snprintf(cert_name, sizeof(cert_name), "%s:%s", token, personality); @@ -1128,7 +1128,7 @@ slapd_SSL_client_auth (LDAP* ld) * the personality for internal tokens. */ token = slapi_ch_strdup(internalTokenName); - strcpy(cert_name, personality); + PL_strncpyz(cert_name, personality, sizeof(cert_name)); slapi_ch_free((void **) &ssltoken); } else { /* external PKCS #11 token - attach token name */ @@ -1371,8 +1371,10 @@ char* slapd_get_tmp_dir() "config_get_instancedir returns NULL Setting tmp dir to default\n"); #if defined( XP_WIN32 ) + ilen = sizeof(tmp); + GetTempPath( ilen, tmp ); + tmp[ilen-1] = (char)0; ilen = strlen(tmp); - GetTempPath( ilen+1, tmp ); /* Remove trailing slash. */ pch = tmp[ilen-1]; if( pch == '\\' || pch == '/' ) diff --git a/ldap/servers/slapd/str2filter.c b/ldap/servers/slapd/str2filter.c index 0be70725..cb65cc97 100644 --- a/ldap/servers/slapd/str2filter.c +++ b/ldap/servers/slapd/str2filter.c @@ -215,6 +215,8 @@ str2simple( char *str , int unescape_filter) LDAPDebug( LDAP_DEBUG_FILTER, "str2simple \"%s\"\n", str, 0, 0 ); + PR_ASSERT(str); + if ( (s = strchr( str, '=' )) == NULL ) { return( NULL ); } diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c index 20e42b95..4bc452fd 100644 --- a/ldap/servers/slapd/task.c +++ b/ldap/servers/slapd/task.c @@ -245,7 +245,7 @@ void slapi_task_log_notice(Slapi_Task *task, char *format, ...) va_end(ap); len = 2 + strlen(buffer) + (task->task_log ? strlen(task->task_log) : 0); - if (len > MAX_SCROLLBACK_BUFFER) { + if ((len > MAX_SCROLLBACK_BUFFER) && task->task_log) { size_t i; char *newbuf; diff --git a/ldap/servers/slapd/tools/mmldif.c b/ldap/servers/slapd/tools/mmldif.c index 68ec793f..63f0ff96 100644 --- a/ldap/servers/slapd/tools/mmldif.c +++ b/ldap/servers/slapd/tools/mmldif.c @@ -655,8 +655,8 @@ int mm_init(int argc, char * argv[]) edfin[ndirectories].end = FALSE; if (emitchanges) { - strcpy(deltaname, *argv); - strcat(deltaname, ".delta"); + PL_strncpyz(deltaname, *argv, sizeof(deltaname)); + PL_strcatn(deltaname, sizeof(deltaname), ".delta"); edfout[ndirectories] = fopen(deltaname, "w"); if (edfout[ndirectories] == NULL) { perror(deltaname); diff --git a/ldap/servers/slapd/util.c b/ldap/servers/slapd/util.c index 7d8fa0b4..bb1b569c 100644 --- a/ldap/servers/slapd/util.c +++ b/ldap/servers/slapd/util.c @@ -411,9 +411,9 @@ rel2abspath( char *relpath ) #else if ( abspath[ 0 ] != '\0' && abspath[ strlen( abspath ) - 1 ] != '/' ) { #endif - strcat( abspath, "/" ); + PL_strcatn( abspath, sizeof(abspath), "/" ); } - strcat( abspath, relpath ); + PL_strcatn( abspath, sizeof(abspath), relpath ); } return( slapi_ch_strdup( abspath )); } |