X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Ffind.c;h=d8829530827d2d05846cc983a1db72233cc12111;hb=1a5755dbbff0fa4d87984cb7d67cb8239fd71a84;hp=287aae39f275fca802ba3948d2ac117d8afee7ba;hpb=3c5b447efd42b03c24104bdc1f3260e879bb1d25;p=libguestfs.git diff --git a/daemon/find.c b/daemon/find.c index 287aae3..d882953 100644 --- a/daemon/find.c +++ b/daemon/find.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,21 +56,27 @@ do_find (char *dir) FILE *fp; char **res = NULL; int size = 0, alloc = 0; - char sysrootdir[PATH_MAX]; + char *sysrootdir; char str[PATH_MAX]; NEED_ROOT (NULL); ABS_PATH (dir, NULL); - snprintf (sysrootdir, sizeof sysrootdir, "/sysroot%s", dir); + sysrootdir = sysroot_path (dir); + if (!sysrootdir) { + reply_with_perror ("malloc"); + return NULL; + } r = stat (sysrootdir, &statbuf); if (r == -1) { reply_with_perror ("%s", dir); + free (sysrootdir); return NULL; } if (!S_ISDIR (statbuf.st_mode)) { reply_with_error ("%s: not a directory", dir); + free (sysrootdir); return NULL; } @@ -81,11 +87,13 @@ do_find (char *dir) cmd = malloc (len); if (!cmd) { reply_with_perror ("malloc"); + free (sysrootdir); return NULL; } strcpy (cmd, "find "); shell_quote (cmd+5, len-5, sysrootdir); + free (sysrootdir); strcat (cmd, " -print0"); if (verbose) @@ -113,7 +121,7 @@ do_find (char *dir) return NULL; } } - if (pclose (fp) == -1) { + if (pclose (fp) != 0) { reply_with_perror ("pclose: find"); free_stringslen (res, size); return NULL;