From: Nicholas Clark Date: Fri, 3 Apr 2009 19:41:48 +0000 (+0100) Subject: In sdbm_open(), replace strcat()s and strcpy()s with memcpy()s. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=081f72ad6fa2b76e0b3cd9046371b2dbd9130114;p=p5sagit%2Fp5-mst-13.2.git In sdbm_open(), replace strcat()s and strcpy()s with memcpy()s. --- diff --git a/ext/SDBM_File/sdbm/sdbm.c b/ext/SDBM_File/sdbm/sdbm.c index 8be9bb9..c5f7aa8 100644 --- a/ext/SDBM_File/sdbm/sdbm.c +++ b/ext/SDBM_File/sdbm/sdbm.c @@ -77,23 +77,28 @@ sdbm_open(register char *file, register int flags, register int mode) register DBM *db; register char *dirname; register char *pagname; - register int n; + size_t filelen; + const size_t dirfext_len = sizeof(DIRFEXT ""); + const size_t pagfext_len = sizeof(PAGFEXT ""); if (file == NULL || !*file) return errno = EINVAL, (DBM *) NULL; /* * need space for two seperate filenames */ - n = strlen(file) * 2 + strlen(DIRFEXT) + strlen(PAGFEXT) + 2; + filelen = strlen(file); - if ((dirname = (char *) malloc((unsigned) n)) == NULL) + if ((dirname = (char *) malloc(filelen + dirfext_len + 1 + + filelen + pagfext_len + 1)) == NULL) return errno = ENOMEM, (DBM *) NULL; /* * build the file names */ - strcat(strcpy(dirname, file), DIRFEXT); - pagname = strcpy(dirname + strlen(dirname) + 1, file); - strcat(pagname, PAGFEXT); + memcpy(dirname, file, filelen); + memcpy(dirname + filelen, DIRFEXT, dirfext_len + 1); + pagname = dirname + filelen + dirfext_len + 1; + memcpy(pagname, file, filelen); + memcpy(pagname + filelen, PAGFEXT, pagfext_len + 1); db = sdbm_prep(dirname, pagname, flags, mode); free((char *) dirname);