From 8b4a28977a13e39489cda61f29eee160e86abde5 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Mon, 25 Jan 1999 23:47:01 +0000 Subject: [PATCH] * prof_tree.c (profile_node_iterator): Added comments indicating that profile_node_iterator, not being an exported interface, returns pointers into the parse tree, and that values should be strdup()'ed before returning them to a calling application. prof_get.c (profile_iterator): Strdup the name and value strings before returning them to the calling application. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11124 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/profile/prof_get.c | 32 +++++++++++++++++++++++++++++++- src/util/profile/prof_tree.c | 9 ++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/util/profile/prof_get.c b/src/util/profile/prof_get.c index ff07bc3ef..094c6a8d3 100644 --- a/src/util/profile/prof_get.c +++ b/src/util/profile/prof_get.c @@ -364,7 +364,37 @@ errcode_t profile_iterator(iter_p, ret_name, ret_value) void **iter_p; char **ret_name, **ret_value; { - return profile_node_iterator(iter_p, 0, ret_name, ret_value); + char *name, *value; + errcode_t retval; + + retval = profile_node_iterator(iter_p, 0, &name, &value); + if (retval) + return retval; + + if (ret_name) { + if (name) { + *ret_name = malloc(strlen(name)+1); + if (!*ret_name) + return ENOMEM; + strcpy(*ret_name, name); + } else + *ret_name = 0; + } + if (ret_value) { + if (value) { + *ret_value = malloc(strlen(value)+1); + if (!*ret_value) { + if (ret_name) { + free(*ret_name); + *ret_name = 0; + } + return ENOMEM; + } + strcpy(*ret_value, value); + } else + *ret_value = 0; + } + return 0; } void profile_release_string(str) diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c index e8257c826..499296c74 100644 --- a/src/util/profile/prof_tree.c +++ b/src/util/profile/prof_tree.c @@ -206,7 +206,7 @@ int profile_is_node_final(node) * * The returned character string in value points to the stored * character string in the parse string. Before this string value is - * returned to a calling application (profile_find_node_relatioon is not an + * returned to a calling application (profile_find_node_relation is not an * exported interface), it should be strdup()'ed. */ errcode_t profile_find_node_relation(section, name, state, ret_name, value) @@ -430,6 +430,13 @@ void profile_node_iterator_free(iter_p) *iter_p = 0; } +/* + * Note: the returned character strings in ret_name and ret_value + * points to the stored character string in the parse string. Before + * this string value is returned to a calling application + * (profile_node_iterator is not an exported interface), it should be + * strdup()'ed. + */ errcode_t profile_node_iterator(iter_p, ret_node, ret_name, ret_value) void **iter_p; struct profile_node **ret_node; -- 2.26.2