[Mobies-commit] [commit] r3646 - UDM/trunk/src/UdmBase

endre at redhat1.isis.vanderbilt.edu endre at redhat1.isis.vanderbilt.edu
Fri Feb 18 14:18:52 CST 2011


Author: endre
Date: Fri Feb 18 14:18:52 2011
New Revision: 3646

Log:
Limit length of filenames of project archives to _MAX_PATH (Win32) or to the value returned by patchconf on Linux

The change prevents huge memory allocations due to corrupt project archives
specifying abnormal filename lengths.

Modified:
   UDM/trunk/src/UdmBase/Project.cpp

Modified: UDM/trunk/src/UdmBase/Project.cpp
==============================================================================
--- UDM/trunk/src/UdmBase/Project.cpp	Fri Feb 18 14:17:06 2011	(r3645)
+++ UDM/trunk/src/UdmBase/Project.cpp	Fri Feb 18 14:18:52 2011	(r3646)
@@ -175,12 +175,18 @@
 
 		while(unz_res == UNZ_OK)
 		{
-			unz_file_info ufi;
-			if (unzGetCurrentFileInfo(zf, &ufi, NULL, 0, NULL, 0, NULL, 0) != UNZ_OK)
-				throw udm_exception("Unknown UNZ error occurred!");
+			long filename_length;
+#ifdef WIN32
+			filename_length = _MAX_PATH;
+#else
+			filename_length = pathconf(temp_path.c_str(), _PC_PATH_MAX);
+			if (filename_length == -1) filename_length = 4096;
+#endif
+			filename_length -= temp_path.length() + strlen(PATHDELIM);
+			char * filename = new char[filename_length];
 
-			char * filename = new char[ufi.size_filename + 1];
-			if (unzGetCurrentFileInfo(zf, NULL, filename, ufi.size_filename + 1, NULL,0,NULL,0) != UNZ_OK)
+			unz_file_info ufi;
+			if (unzGetCurrentFileInfo(zf, &ufi, filename, filename_length, NULL, 0, NULL, 0) != UNZ_OK)
 				throw udm_exception("Unknown UNZ error occurred!");
 
 			string tempfilename = temp_path + PATHDELIM + filename;


More information about the Mobies-commit mailing list