commons-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=810127&view=rev
Log:
Reserve 12 bytes for temp pattern

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/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=810127&r1=810126&r2=810127&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:09:29 2009
@@ -25,6 +25,8 @@
 #include "acr_env.h"
 #include "acr_file.h"
 
+#define TMP_PATH_MAX    (PATH_MAX - 12)
+
 static const char *_try_dirs[] = {
     "/tmp",
     "/usr/tmp",
@@ -68,7 +70,10 @@
     acr_file_t *fp;
 
     if (tmpath) {
-        strlcpy(name, tmpath, PATH_MAX);
+        if (strlcpy(name, tmpath, TMP_PATH_MAX) >= TMP_PATH_MAX) {
+            ACR_THROW_IO_IF_ERR(ACR_ENODIR);
+            return -1;
+        }
         strlcat(name, "/",    PATH_MAX);
     }
     strlcat(name, prefix,   PATH_MAX);
@@ -117,7 +122,10 @@
 
     for (;;) {
         if (tmpath) {
-            strlcpy(name, tmpath, PATH_MAX);
+            if (strlcpy(name, tmpath, TMP_PATH_MAX) >= TMP_PATH_MAX) {
+                ACR_THROW_IO_IF_ERR(ACR_ENODIR);
+                return NULL;
+            }
             strlcat(name, "/",    PATH_MAX);
         }
         strlcat(name, prefix,   PATH_MAX);
@@ -168,7 +176,7 @@
 
 ACR_DECLARE(const char *) ACR_TempPathGet(JNIEnv *_E)
 {
-    static char _temp_path[PATH_MAX] = "";
+    static char _temp_path[TMP_PATH_MAX] = "";
     int i = 0;
 
     if (_temp_path[0])
@@ -176,24 +184,41 @@
     while (_try_envs[i]) {
         char *val = ACR_EnvGet(_try_envs[i]);
         if (val && *val) {
-            if (_temp_test(val)) {
-                strlcpy(_temp_path, val, PATH_MAX);
-                break;
+            if (strlen(val) < TMP_PATH_MAX) {
+                if (_temp_test(val)) {
+                    strlcpy(_temp_path, val, TMP_PATH_MAX);
+                    break;
+                }
             }
         }
         i++;
     }
-    if (_temp_path[0])
+    if (_temp_path[0]) {
         return _temp_path;
+    }
     i = 0;
     while (_try_dirs[i]) {
-        if (_temp_test(_try_dirs[i])) {
-            strlcpy(_temp_path, _try_dirs[i], PATH_MAX);
-            break;
+        if (strlen(_try_dirs[i]) < TMP_PATH_MAX) {
+            if (_temp_test(_try_dirs[i])) {
+                strlcpy(_temp_path, _try_dirs[i], TMP_PATH_MAX);
+                break;
+            }
         }
         i++;
     }
-
+    if (_temp_path[0]) {
+        return _temp_path;
+    }
+    else {
+        /* Finally try the users $HOME */
+        char *val = ACR_EnvGet("HOME");
+        if (val && *val) {
+            if (strlen(val) < TMP_PATH_MAX) {
+                if (_temp_test(val))
+                    strlcpy(_temp_path, val, TMP_PATH_MAX);
+            }
+        }
+    }
     if (_temp_path[0]) {
         return _temp_path;
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c?rev=810127&r1=810126&r2=810127&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c Tue Sep  1 17:09:29 2009
@@ -24,6 +24,15 @@
 #include "acr_env.h"
 #include "acr_file.h"
 
+static const wchar_t *_try_envs[] = {
+    L"TMP",
+    L"TEMP",
+    L"TMPDIR",
+    L"TEMPDIR",
+    L"USERPROFILE",
+    NULL
+};
+
 static int tmp_file_cleanup(void *file, int type, unsigned int flags)
 {
     acr_file_t *fp = (acr_file_t *)file;



Mime
View raw message