commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r810128 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
Date Tue, 01 Sep 2009 17:12:33 GMT
Author: mturk
Date: Tue Sep  1 17:12:33 2009
New Revision: 810128

URL: http://svn.apache.org/viewvc?rev=810128&view=rev
Log:
Guard against temp path overflows

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c?rev=810128&r1=810127&r2=810128&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c Tue Sep  1 17:12:33 2009
@@ -71,13 +71,19 @@
 
     if (tmpath) {
         if (strlcpy(name, tmpath, TMP_PATH_MAX) >= TMP_PATH_MAX) {
-            ACR_THROW_IO_IF_ERR(ACR_ENODIR);
+            ACR_THROW_IO_IF_ERR(ACR_E2BIG);
             return -1;
         }
         strlcat(name, "/",    PATH_MAX);
     }
     strlcat(name, prefix,   PATH_MAX);
-    strlcat(name, "XXXXXX", PATH_MAX);
+    if (strlcat(name, "XXXXXX", PATH_MAX) >= PATH_MAX) {
+        /* Truncation occurred. We dont have enough space
+         * to create temp file template
+         */
+        ACR_THROW_IO_IF_ERR(ACR_E2BIG);
+        return -1;
+    }
 
     fd = mkstemp(name);
     if (fd < 0) {
@@ -123,12 +129,12 @@
     for (;;) {
         if (tmpath) {
             if (strlcpy(name, tmpath, TMP_PATH_MAX) >= TMP_PATH_MAX) {
-                ACR_THROW_IO_IF_ERR(ACR_ENODIR);
+                ACR_THROW_IO_IF_ERR(ACR_E2BIG);
                 return NULL;
             }
-            strlcat(name, "/",    PATH_MAX);
+            strlcat(name, "/", PATH_MAX);
         }
-        strlcat(name, prefix,   PATH_MAX);
+        strlcat(name, prefix, PATH_MAX);
         if (strlcat(name, "XXXXXX", PATH_MAX) >= PATH_MAX) {
             /* Truncation occurred. We dont have enough space
              * to create temp file template



Mime
View raw message