public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/3] lib: Add SAFE_CHROOT(path) macro
@ 2018-06-20 15:48 Petr Vorel
  2018-06-20 15:48 ` [LTP] [PATCH v2 2/3] lib: Introduce TESTPTR() Petr Vorel
  2018-06-20 15:48 ` [LTP] [PATCH v2 3/3] cve/cve-2018-1000001: Add Realpath Buffer Underflow test Petr Vorel
  0 siblings, 2 replies; 6+ messages in thread
From: Petr Vorel @ 2018-06-20 15:48 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
v1->v2:
* new API only
---
 include/tst_safe_macros.h |  6 +++++-
 lib/tst_safe_macros.c     | 13 +++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 75c2a0803..1ad9c71b2 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2015 Linux Test Project
+ * Copyright (c) 2010-2018 Linux Test Project
  * Copyright (c) 2011-2015 Cyril Hrubis <chrubis@suse.cz>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -48,6 +48,10 @@
 #define SAFE_CREAT(pathname, mode) \
 	safe_creat(__FILE__, __LINE__, NULL, (pathname), (mode))
 
+#define SAFE_CHROOT(path) \
+	safe_chroot(__FILE__, __LINE__, (path))
+int safe_chroot(const char *file, const int lineno, const char *path);
+
 #define SAFE_DIRNAME(path) \
 	safe_dirname(__FILE__, __LINE__, NULL, (path))
 
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index e152bff7f..17384f32c 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -152,3 +152,16 @@ struct group *safe_getgrnam(const char *file, const int lineno,
 
 	return rval;
 }
+
+int safe_chroot(const char *file, const int lineno, const char *path)
+{
+	int rval;
+
+	rval = chroot(path);
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "chroot(%s) failed", path);
+	}
+
+	return rval;
+}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-06-21 14:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-20 15:48 [LTP] [PATCH v2 1/3] lib: Add SAFE_CHROOT(path) macro Petr Vorel
2018-06-20 15:48 ` [LTP] [PATCH v2 2/3] lib: Introduce TESTPTR() Petr Vorel
2018-06-20 15:48 ` [LTP] [PATCH v2 3/3] cve/cve-2018-1000001: Add Realpath Buffer Underflow test Petr Vorel
2018-06-21  9:34   ` Cyril Hrubis
2018-06-21 14:10     ` Petr Vorel
2018-06-21 14:12       ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox