summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-04-03 20:41:48 +0100
committerNicholas Clark <nick@ccl4.org>2009-04-03 20:41:48 +0100
commit081f72ad6fa2b76e0b3cd9046371b2dbd9130114 (patch)
treea69712f735147548c28f20d0b23f2b032164d338
parentae2e8cc73fae1410e6d42ea6108d013cdd5c0d5f (diff)
downloadperl-081f72ad6fa2b76e0b3cd9046371b2dbd9130114.tar.gz
In sdbm_open(), replace strcat()s and strcpy()s with memcpy()s.
-rw-r--r--ext/SDBM_File/sdbm/sdbm.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/SDBM_File/sdbm/sdbm.c b/ext/SDBM_File/sdbm/sdbm.c
index 8be9bb9b5c..c5f7aa8059 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);