Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 165940 - media-libs/jpeg: exifautotran uses a hard-coded temp file
Summary: media-libs/jpeg: exifautotran uses a hard-coded temp file
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal
Assignee: Gentoo Graphics Project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-08 16:54 UTC by Andrew Aylett
Modified: 2007-02-09 06:42 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Aylett 2007-02-08 16:54:31 UTC
The exifautotran script included in media-libs/jpeg uses a hardcoded name 'tempfile' for temporary file operations.  This will also obviously fail if you don't have write privilages for the current directory.

The security aspect is a potential symlink vulnerability, as well as the issue of the script overwriting any other 'tempfile' you might have in the current directory.  It also makes running multiple instances of the script somewhat challenging.

Reproducible: Always

Steps to Reproduce:
1. Create a file in the local directory called 'tempfile'
2. Find a JPEG file where the exif data says the image requires rotation (http://old.aylett.co.uk/~axa/img_0183.jpg)
3. Run exifautotran on that jpeg file
4. Run exifautotran on a fresh instance of the jpeg file from a directory you have no write access to

Actual Results:  
The file created in step one is gone, step four fails

Expected Results:  
The file is left intact, both steps three and four result in a rotated jpeg file

Simple fix to use mktemp instead:

--- exifautotran~       2007-01-02 16:44:23.000000000 +0000
+++ exifautotran        2007-02-08 16:24:38.000000000 +0000
@@ -27,14 +27,15 @@
  8) transform="-rotate 270";;
  *) transform="";;
  esac
+ TMPFILE=`mktemp` || exit 1
  if test -n "$transform"; then
   echo Executing: jpegtran -copy all $transform $i >&2
-  jpegtran -copy all $transform "$i" > tempfile
+  jpegtran -copy all $transform "$i" > $TMPFILE
   if test $? -ne 0; then
    echo Error while transforming $i - skipped. >&2
+   rm $TMPFILE
   else
    rm "$i"
-   mv tempfile "$i"
+   mv $TMPFILE "$i"
    jpegexiforient -1 "$i" > /dev/null
   fi
  fi
Comment 1 Tavis Ormandy (RETIRED) gentoo-dev 2007-02-08 17:07:15 UTC
Thanks for the report, although its not good practice for the reasons you describe, the security team wont usually consider using the cwd insecurely as a security issue unless there are exceptional circumstances. However, the maintainer may wish to apply your patch anyway.

Believe it or not, this is actually reccommended by several well published secure coding guides (eg, check out the Secure Programming HOWTO, section 7.10.1.2).

Reassinging to graphics team...
Comment 2 SpanKY gentoo-dev 2007-02-09 06:42:50 UTC
fixed in jpeg-6b-r8