[MOAB-dev] r5925 - MOAB/trunk/src/io

tautges at mcs.anl.gov tautges at mcs.anl.gov
Tue Dec 18 09:58:23 CST 2012


Author: tautges
Date: 2012-12-18 09:58:23 -0600 (Tue, 18 Dec 2012)
New Revision: 5925

Modified:
   MOAB/trunk/src/io/WriteNCDF.cpp
Log:
Fixing potential buffer overflow pointed out by Klokworks.



Modified: MOAB/trunk/src/io/WriteNCDF.cpp
===================================================================
--- MOAB/trunk/src/io/WriteNCDF.cpp	2012-12-18 05:58:06 UTC (rev 5924)
+++ MOAB/trunk/src/io/WriteNCDF.cpp	2012-12-18 15:58:23 UTC (rev 5925)
@@ -1674,10 +1674,8 @@
 
       /* store element type as attribute of connectivity variable */
 
-    char element_type_string[ExoIIInterface::MAX_STR_LENGTH+1];
-    strcpy(element_type_string, ExoIIUtil::ElementTypeNames[ block.element_type ]);
-
-    if (NC_NOERR != nc_put_att_text(ncFile, connect, "elem_type", strlen(element_type_string), element_type_string))
+    std::string element_type_string(ExoIIUtil::ElementTypeNames[ block.element_type ]);
+    if (NC_NOERR != nc_put_att_text(ncFile, connect, "elem_type", element_type_string.length(), element_type_string.c_str()))
     {
       mWriteIface->report_error("WriteNCDF: failed to store element type name %d", (int)block.element_type);
       return (MB_FAILURE);



More information about the moab-dev mailing list