Richard W.M. Jones
2017-Mar-13 12:26 UTC
[Libguestfs] [PATCH] mllib: Add a binding for realpath(3).
I was planning to use this function to harden the code in v2v/input_ova.ml against malicious OVA files. However I didn't complete that work. Hate to see a good commit go to waste ... Rich.
Richard W.M. Jones
2017-Mar-13 12:26 UTC
[Libguestfs] [PATCH] mllib: Add a binding for realpath(3).
This is a copy of the supermin binding: https://github.com/libguestfs/supermin/tree/master/src realpath* --- mllib/unix_utils-c.c | 18 ++++++++++++++++++ mllib/unix_utils.ml | 4 ++++ mllib/unix_utils.mli | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/mllib/unix_utils-c.c b/mllib/unix_utils-c.c index f5aaaf6..7e90541 100644 --- a/mllib/unix_utils-c.c +++ b/mllib/unix_utils-c.c @@ -25,6 +25,7 @@ #include <unistd.h> #include <fcntl.h> #include <fnmatch.h> +#include <limits.h> #include <errno.h> #include <sys/types.h> #include <sys/statvfs.h> @@ -57,6 +58,7 @@ extern value guestfs_int_mllib_fnmatch (value patternv, value strv, value flagsv extern value guestfs_int_mllib_sync (value unitv); extern value guestfs_int_mllib_fsync_file (value filenamev); extern value guestfs_int_mllib_mkdtemp (value val_pattern); +extern value guestfs_int_mllib_realpath (value pathv); extern value guestfs_int_mllib_statvfs_free_space (value pathv); /* NB: This is a "noalloc" call. */ @@ -196,6 +198,22 @@ guestfs_int_mllib_mkdtemp (value val_pattern) } value +guestfs_int_mllib_realpath (value pathv) +{ + CAMLparam1 (pathv); + CAMLlocal1 (rv); + char *r; + + r = realpath (String_val (pathv), NULL); + if (r == NULL) + unix_error (errno, (char *) "realpath", pathv); + + rv = caml_copy_string (r); + free (r); + CAMLreturn (rv); +} + +value guestfs_int_mllib_statvfs_free_space (value pathv) { CAMLparam1 (pathv); diff --git a/mllib/unix_utils.ml b/mllib/unix_utils.ml index 66b6e4f..8ac3683 100644 --- a/mllib/unix_utils.ml +++ b/mllib/unix_utils.ml @@ -56,6 +56,10 @@ module Mkdtemp = struct mkdtemp (Filename.concat base_dir (prefix ^ "XXXXXX" ^ suffix)) end +module Realpath = struct + external realpath : string -> string = "guestfs_int_mllib_realpath" +end + module StatVFS = struct external free_space : string -> int64 "guestfs_int_mllib_statvfs_free_space" diff --git a/mllib/unix_utils.mli b/mllib/unix_utils.mli index 0a4c1b3..4795cb3 100644 --- a/mllib/unix_utils.mli +++ b/mllib/unix_utils.mli @@ -88,6 +88,11 @@ module Mkdtemp : sig [Filename.temp_dir_name] is used. *) end +module Realpath : sig + val realpath : string -> string + (** [realpath(3)] returns the canonicalized absolute pathname. *) +end + module StatVFS : sig val free_space : string -> int64 (** [free_space path] returns the free space available on the -- 2.9.3
Pino Toscano
2017-Mar-13 12:46 UTC
Re: [Libguestfs] [PATCH] mllib: Add a binding for realpath(3).
In data lunedì 13 marzo 2017 12:26:12 CET, Richard W.M. Jones ha scritto:> This is a copy of the supermin binding: > > https://github.com/libguestfs/supermin/tree/master/src realpath* > ---LGTM, just one small note:> diff --git a/mllib/unix_utils-c.c b/mllib/unix_utils-c.c > index f5aaaf6..7e90541 100644 > --- a/mllib/unix_utils-c.c > +++ b/mllib/unix_utils-c.c > @@ -25,6 +25,7 @@ > #include <unistd.h> > #include <fcntl.h> > #include <fnmatch.h> > +#include <limits.h>Most probably this header is not needed. Thanks, -- Pino Toscano
Maybe Matching Threads
- [PATCH v2 0/2] builder: Choose better weights in the planner.
- [PATCH v3 0/2] builder: Choose better weights in the planner.
- [PATCH] mllib: Add a binding for realpath(3).
- [PATCH 0/3] v2v: vCenter: Remove proxy environment variables
- [PATCH 0/2] builder: Choose better weights in the planner.