From 760476bccf98912ae811cab3ccad2d173d62c940 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Sat, 2 Jan 1999 06:38:49 +0000 Subject: [PATCH] prof_tree.c (profile_node_iterator): Make sure the pointer to the iterator function is non-NULL before checking the magic value. prof_file.c (profile_open_file): Add ability to parse filenames that begin with "~/" and substitute it with "$HOME/". git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11096 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/profile/ChangeLog | 11 +++++++++++ src/util/profile/prof_file.c | 16 ++++++++++++++-- src/util/profile/prof_tree.c | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index 554357a58..035911559 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,14 @@ +1998-12-31 Theodore Ts'o + + * prof_tree.c (profile_node_iterator): Make sure the pointer to + the iterator function is non-NULL before checking the + magic value. + +1998-12-15 Theodore Ts'o + + * prof_file.c (profile_open_file): Add ability to parse filenames + that begin with "~/" and substitute it with "$HOME/". + 1998-12-04 Theodore Ts'o * prof_get.c: Add new public profile_iterator functions for diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index 070cbeffc..fde687482 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -29,17 +29,29 @@ errcode_t profile_open_file(filename, ret_prof) { prf_file_t prf; errcode_t retval; + char *home_env = 0; + int len; prf = malloc(sizeof(struct _prf_file_t)); if (!prf) return ENOMEM; memset(prf, 0, sizeof(struct _prf_file_t)); - prf->filename = malloc(strlen(filename)+1); + len = strlen(filename)+1; + if (filename[0] == '~' && filename[1] == '/') { + home_env = getenv("HOME"); + if (home_env) + len += strlen(home_env); + } + prf->filename = malloc(len); if (!prf->filename) { free(prf); return ENOMEM; } - strcpy(prf->filename, filename); + if (home_env) { + strcpy(prf->filename, home_env); + strcat(prf->filename, filename+1); + } else + strcpy(prf->filename, filename); prf->magic = PROF_MAGIC_FILE; retval = profile_update_file(prf); diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c index ddfa08f44..e8257c826 100644 --- a/src/util/profile/prof_tree.c +++ b/src/util/profile/prof_tree.c @@ -441,7 +441,7 @@ errcode_t profile_node_iterator(iter_p, ret_node, ret_name, ret_value) errcode_t retval; int skip_num = 0; - if (iter->magic != PROF_MAGIC_ITERATOR) + if (!iter || iter->magic != PROF_MAGIC_ITERATOR) return PROF_MAGIC_ITERATOR; /* * If the file has changed, then the node pointer is invalid, -- 2.26.2