subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1131403 - /subversion/trunk/subversion/libsvn_subr/magic.c
Date Sat, 04 Jun 2011 13:59:10 GMT
Author: stsp
Date: Sat Jun  4 13:59:09 2011
New Revision: 1131403

URL: http://svn.apache.org/viewvc?rev=1131403&view=rev
Log:
* subversion/libsvn_subr/magic.c: 
  (svn_magic__detect_binary_mimetype): libmagic cannot be trusted to always
    return valid mime types so validate the mime type before using it.

Found by: svn-x64-centos-gcc

Modified:
    subversion/trunk/subversion/libsvn_subr/magic.c

Modified: subversion/trunk/subversion/libsvn_subr/magic.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/magic.c?rev=1131403&r1=1131402&r2=1131403&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/magic.c (original)
+++ subversion/trunk/subversion/libsvn_subr/magic.c Sat Jun  4 13:59:09 2011
@@ -30,6 +30,7 @@
 #include <apr_file_info.h>
 
 #include "svn_io.h"
+#include "svn_types.h"
 #include "svn_pools.h"
 #include "svn_error.h"
 
@@ -122,6 +123,7 @@ svn_magic__detect_binary_mimetype(const 
             magic_mimetype = NULL;
           else
            {
+             svn_error_t *err;
 #ifndef MAGIC_MIME_TYPE
              char *p;
 
@@ -130,9 +132,24 @@ svn_magic__detect_binary_mimetype(const 
              if (p)
               *p = '\0';
 #endif
-             /* The string is allocated from memory managed by libmagic so
-              * we must copy it to the result pool. */
-             magic_mimetype = apr_pstrdup(result_pool, magic_mimetype);
+            /* Make sure we got a valid mime type. */
+            err = svn_mime_type_validate(magic_mimetype, scratch_pool);
+            if (err)
+              {
+                if (err->apr_err == SVN_ERR_BAD_MIME_TYPE)
+                  {
+                    svn_error_clear(err);
+                    magic_mimetype = NULL;
+                  }
+                else
+                  return svn_error_return(err);
+              }
+            else
+              {
+                /* The string is allocated from memory managed by libmagic
+                 * so we must copy it to the result pool. */
+                magic_mimetype = apr_pstrdup(result_pool, magic_mimetype);
+              }
            }
         }
     }



Mime
View raw message