diff options
| author | Greg Hudson <ghudson@mit.edu> | 2008-10-20 21:14:47 +0000 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2008-10-20 21:14:47 +0000 |
| commit | ae423f53214830de1367627180031283de998746 (patch) | |
| tree | f3268a5a9d718d570883bf296c52c117e0dfc709 /src/util/profile | |
| parent | cdea7397975a960e3c02479f8aa4ede0bc349105 (diff) | |
| download | krb5-ae423f53214830de1367627180031283de998746.tar.gz krb5-ae423f53214830de1367627180031283de998746.tar.xz krb5-ae423f53214830de1367627180031283de998746.zip | |
Use asprintf instead of malloc/strcpy/strcat in many places
ticket: 6200
status: open
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20901 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/profile')
| -rw-r--r-- | src/util/profile/prof_file.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index 13d8860e8..4851788e6 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -198,7 +198,6 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, prf_file_t prf; errcode_t retval; char *home_env = 0; - unsigned int len; prf_data_t data; char *expanded_filename; @@ -214,7 +213,6 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, memset(prf, 0, sizeof(struct _prf_file_t)); prf->magic = PROF_MAGIC_FILE; - len = strlen(filespec)+1; if (filespec[0] == '~' && filespec[1] == '/') { home_env = getenv("HOME"); #ifdef HAVE_PWD_H @@ -229,19 +227,17 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, home_env = pw->pw_dir; } #endif - if (home_env) - len += strlen(home_env); } - expanded_filename = malloc(len); + if (home_env) { + if (asprintf(&expanded_filename, "%s%s", home_env, + filespec + 1) < 0) + expanded_filename = 0; + } else + expanded_filename = strdup(filespec); if (expanded_filename == 0) { free(prf); return ENOMEM; } - if (home_env) { - strcpy(expanded_filename, home_env); - strcat(expanded_filename, filespec+1); - } else - memcpy(expanded_filename, filespec, len); retval = k5_mutex_lock(&g_shared_trees_mutex); if (retval) { |
