|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] xenstore: In xenstore_client, avoid stack buffer in recursive function
commit 848a23560fc847a4a58db138c39a0cfa4ff96f59
Author: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
AuthorDate: Fri Jun 20 11:54:56 2014 +0100
Commit: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CommitDate: Mon Jul 14 16:07:50 2014 +0100
xenstore: In xenstore_client, avoid stack buffer in recursive function
do_ls is recursive. It had a buffer of size around 5K allocated on
the stack. This combination is not a very good idea: some
environments (eg, Mini-OS) have limited stack sizes (eg 64K).
Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
tools/xenstore/xenstore_client.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 56b9309..1054f18 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -128,11 +128,15 @@ static int show_whole_path = 0;
static void do_ls(struct xs_handle *h, char *path, int cur_depth, int
show_perms)
{
char **e;
- char newpath[STRING_MAX], *val;
+ char *newpath, *val;
int newpath_len;
int i;
unsigned int num, len;
+ newpath = malloc(STRING_MAX);
+ if (!newpath)
+ err(1, "malloc in do_ls");
+
e = xs_directory(h, XBT_NULL, path, &num);
if (e == NULL)
err(1, "xs_directory (%s)", path);
@@ -144,7 +148,7 @@ static void do_ls(struct xs_handle *h, char *path, int
cur_depth, int show_perms
int linewid;
/* Compose fullpath */
- newpath_len = snprintf(newpath, sizeof(newpath), "%s%s%s", path,
+ newpath_len = snprintf(newpath, STRING_MAX, "%s%s%s", path,
path[strlen(path)-1] == '/' ? "" : "/",
e[i]);
@@ -161,7 +165,7 @@ static void do_ls(struct xs_handle *h, char *path, int
cur_depth, int show_perms
}
/* Fetch value */
- if ( newpath_len < sizeof(newpath) ) {
+ if ( newpath_len < STRING_MAX ) {
val = xs_read(h, XBT_NULL, newpath, &len);
}
else {
@@ -217,6 +221,7 @@ static void do_ls(struct xs_handle *h, char *path, int
cur_depth, int show_perms
do_ls(h, newpath, cur_depth+1, show_perms);
}
free(e);
+ free(newpath);
}
static void
--
generated by git-patchbot for /home/xen/git/xen.git#master
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |