You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2008/09/15 09:54:00 UTC

svn commit: r695370 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c

Author: hindessm
Date: Mon Sep 15 00:54:00 2008
New Revision: 695370

URL: http://svn.apache.org/viewvc?rev=695370&view=rev
Log:
Throw exceptions rather than silently truncate paths.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c?rev=695370&r1=695369&r2=695370&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c Mon Sep 15 00:54:00 2008
@@ -30,7 +30,10 @@
   I_32 result;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -45,7 +48,10 @@
   I_32 result;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -64,7 +70,7 @@
 
   PORT_ACCESS_FROM_ENV (env);
   jsize length = (*env)->GetArrayLength (env, path);
-  char pathCopy[HyMaxPath];
+  char pathCopy[HyMaxPath+1]; // allow room to add trailing /
   char filename[HyMaxPath];
   I_32 result = 0, index;
   I_32 numEntries = 0;
@@ -75,7 +81,10 @@
   dirList = NULL;
   currentEntry = NULL;
 
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length >= HyMaxPath) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   if (length >= 1 && pathCopy[length - 1] != '\\'
       && pathCopy[length - 1] != '/')
@@ -154,7 +163,10 @@
   I_32 result;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -169,7 +181,10 @@
   I_32 result;
   char pathCopy[HyMaxPath];
   jsize length = (*env)->GetArrayLength (env, path);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -184,7 +199,10 @@
   I_32 result;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -200,7 +218,10 @@
   I_64 result;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -216,7 +237,10 @@
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
 
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -265,7 +289,10 @@
   I_32 result;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path length exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -282,11 +309,17 @@
   jsize length;
   char pathExistCopy[HyMaxPath], pathNewCopy[HyMaxPath];
   length = (*env)->GetArrayLength (env, pathExist);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "old path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, pathExist, 0, length, (jbyte *)pathExistCopy));
   pathExistCopy[length] = '\0';
   length = (*env)->GetArrayLength (env, pathNew);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "new path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, pathNew, 0, length, (jbyte *)pathNewCopy));
   pathNewCopy[length] = '\0';
   ioh_convertToPlatform (pathExistCopy);
@@ -305,7 +338,10 @@
   jsize answerlen;
   char pathCopy[HyMaxPath];
   U_32 length = (U_32) (*env)->GetArrayLength (env, path);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   (*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy);
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -326,7 +362,10 @@
   IDATA portFD;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -394,7 +433,10 @@
   I_32 result;
   char pathCopy[HyMaxPath];
   jsize length = (*env)->GetArrayLength (env, path);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -409,7 +451,10 @@
   I_32 result;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -425,7 +470,10 @@
 {
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -457,7 +505,10 @@
   I_32 result;
   char pathCopy[HyMaxPath];
   jsize length = (*env)->GetArrayLength (env, path);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -472,7 +523,10 @@
   I_32 result;
   char pathCopy[HyMaxPath];
   jsize length = (*env)->GetArrayLength (env, path);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
@@ -487,7 +541,10 @@
   jsize answerlen;
   char pathCopy[HyMaxPath];
   U_32 length = (U_32) (*env)->GetArrayLength (env, path);
-  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  if (length > HyMaxPath-1) {
+    throwJavaIoIOException(env, "path exceeds maximum supported length");
+    return 0;
+  }
   (*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy);
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);