git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
README: virtio-serial is required.
[libguestfs.git]
/
daemon
/
strings.c
diff --git
a/daemon/strings.c
b/daemon/strings.c
index
89e04a8
..
f08401b
100644
(file)
--- a/
daemon/strings.c
+++ b/
daemon/strings.c
@@
-21,31
+21,38
@@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
#include "daemon.h"
#include "actions.h"
char **
#include "daemon.h"
#include "actions.h"
char **
-do_strings_e (c
har *encoding,
char *path)
+do_strings_e (c
onst char *encoding, const
char *path)
{
{
- char *buf;
- int r;
+ int fd, flags, r;
char *out, *err;
char **lines;
char *out, *err;
char **lines;
- NEED_ROOT (NULL);
- ABS_PATH (path, return NULL);
+ if (strlen (encoding) != 1 ||
+ strchr ("sSblBL", encoding[0]) == NULL) {
+ reply_with_error ("%s: invalid encoding", encoding);
+ return NULL;
+ }
+
+ CHROOT_IN;
+ fd = open (path, O_RDONLY);
+ CHROOT_OUT;
- buf = sysroot_path (path);
- if (!buf) {
- reply_with_perror ("malloc");
+ if (fd == -1) {
+ reply_with_perror ("%s", path);
return NULL;
}
return NULL;
}
-
r = command (&out, &err, "strings", "-e", encoding, buf, NULL)
;
-
free (buf
);
+
flags = COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN | fd
;
+
r = commandf (&out, &err, flags, "strings", "-e", encoding, NULL
);
if (r == -1) {
if (r == -1) {
- reply_with_error ("
strings:
%s: %s", path, err);
+ reply_with_error ("%s: %s", path, err);
free (err);
free (out);
return NULL;
free (err);
free (out);
return NULL;
@@
-64,7
+71,7
@@
do_strings_e (char *encoding, char *path)
}
char **
}
char **
-do_strings (char *path)
+do_strings (c
onst c
har *path)
{
return do_strings_e ("s", path);
}
{
return do_strings_e ("s", path);
}