Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH v4] patch.bbclass: increase security
@ 2012-09-14 14:25 Constantin Musca
  2012-09-16 19:52 ` Saul Wold
  2012-09-16 20:04 ` Chris Larson
  0 siblings, 2 replies; 3+ messages in thread
From: Constantin Musca @ 2012-09-14 14:25 UTC (permalink / raw)
  To: openembedded-core; +Cc: Constantin Musca

- Use mkdtemp for generating temp dir names
- Use bb.utils.remove for removing temp dirs
- Add comment for explaining the "patch" workaround

[YOCTO #3070]

Signed-off-by: Constantin Musca <constantinx.musca@intel.com>
---
 meta/classes/patch.bbclass |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
index d010438..ed12802 100644
--- a/meta/classes/patch.bbclass
+++ b/meta/classes/patch.bbclass
@@ -139,11 +139,11 @@ python patch_do_patch() {
     path = os.getenv('PATH')
     os.putenv('PATH', d.getVar('PATH', True))
 
-    import shutil
-    process_tmpdir = os.path.join('/tmp', str(os.getpid()))
-    if os.path.exists(process_tmpdir):
-        shutil.rmtree(process_tmpdir)
-    os.makedirs(process_tmpdir)
+    # We must use one TMPDIR per process so that the "patch" processes
+    # don't generate the same temp file name.
+
+    import tempfile
+    process_tmpdir = tempfile.mkdtemp()
     os.environ['TMPDIR'] = process_tmpdir
 
     for patch in src_patches(d):
@@ -168,15 +168,15 @@ python patch_do_patch() {
         try:
             patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
         except Exception as exc:
-            shutil.rmtree(process_tmpdir)
+            bb.utils.remove(process_tmpdir, True)
             bb.fatal(str(exc))
         try:
             resolver.Resolve()
         except bb.BBHandledException as e:
-            shutil.rmtree(process_tmpdir)
+            bb.utils.remove(process_tmpdir, True)
             bb.fatal(str(e))
 
-    shutil.rmtree(process_tmpdir)
+    bb.utils.remove(process_tmpdir, True)
 }
 patch_do_patch[vardepsexclude] = "PATCHRESOLVE"
 
-- 
1.7.9.5




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

* Re: [PATCH v4] patch.bbclass: increase security
  2012-09-14 14:25 [PATCH v4] patch.bbclass: increase security Constantin Musca
@ 2012-09-16 19:52 ` Saul Wold
  2012-09-16 20:04 ` Chris Larson
  1 sibling, 0 replies; 3+ messages in thread
From: Saul Wold @ 2012-09-16 19:52 UTC (permalink / raw)
  To: Constantin Musca; +Cc: openembedded-core

On 09/14/2012 07:25 AM, Constantin Musca wrote:
> - Use mkdtemp for generating temp dir names
> - Use bb.utils.remove for removing temp dirs
> - Add comment for explaining the "patch" workaround
>
> [YOCTO #3070]
>
> Signed-off-by: Constantin Musca <constantinx.musca@intel.com>
> ---
>   meta/classes/patch.bbclass |   16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
> index d010438..ed12802 100644
> --- a/meta/classes/patch.bbclass
> +++ b/meta/classes/patch.bbclass
> @@ -139,11 +139,11 @@ python patch_do_patch() {
>       path = os.getenv('PATH')
>       os.putenv('PATH', d.getVar('PATH', True))
>
> -    import shutil
> -    process_tmpdir = os.path.join('/tmp', str(os.getpid()))
> -    if os.path.exists(process_tmpdir):
> -        shutil.rmtree(process_tmpdir)
> -    os.makedirs(process_tmpdir)
> +    # We must use one TMPDIR per process so that the "patch" processes
> +    # don't generate the same temp file name.
> +
> +    import tempfile
> +    process_tmpdir = tempfile.mkdtemp()
>       os.environ['TMPDIR'] = process_tmpdir
>
>       for patch in src_patches(d):
> @@ -168,15 +168,15 @@ python patch_do_patch() {
>           try:
>               patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
>           except Exception as exc:
> -            shutil.rmtree(process_tmpdir)
> +            bb.utils.remove(process_tmpdir, True)
>               bb.fatal(str(exc))
>           try:
>               resolver.Resolve()
>           except bb.BBHandledException as e:
> -            shutil.rmtree(process_tmpdir)
> +            bb.utils.remove(process_tmpdir, True)
>               bb.fatal(str(e))
>
> -    shutil.rmtree(process_tmpdir)
> +    bb.utils.remove(process_tmpdir, True)
>   }
>   patch_do_patch[vardepsexclude] = "PATCHRESOLVE"
>
>
Merged into OE-Core

Thanks
	Sau!




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

* Re: [PATCH v4] patch.bbclass: increase security
  2012-09-14 14:25 [PATCH v4] patch.bbclass: increase security Constantin Musca
  2012-09-16 19:52 ` Saul Wold
@ 2012-09-16 20:04 ` Chris Larson
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Larson @ 2012-09-16 20:04 UTC (permalink / raw)
  To: Constantin Musca; +Cc: openembedded-core

On Fri, Sep 14, 2012 at 7:25 AM, Constantin Musca
<constantinx.musca@intel.com> wrote:
> -            shutil.rmtree(process_tmpdir)
> +            bb.utils.remove(process_tmpdir, True)

In the future, I'd suggest leveraging the ability to pass arguments by
name to clarify the meaning of the boolean argument:

    bb.utils.remove(process_tmpdir, recurse=True).

This makes it a bit more clear when reading the code in the future.
-- 
Christopher Larson



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

end of thread, other threads:[~2012-09-16 20:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14 14:25 [PATCH v4] patch.bbclass: increase security Constantin Musca
2012-09-16 19:52 ` Saul Wold
2012-09-16 20:04 ` Chris Larson

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