[MOAB-dev] r3226 - MOAB/trunk/tools/iMesh

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Mon Oct 19 20:57:17 CDT 2009


Author: kraftche
Date: 2009-10-19 20:57:17 -0500 (Mon, 19 Oct 2009)
New Revision: 3226

Modified:
   MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
Log:
 o add missing includes
 o fix potential buffer overflow in error handling
 o fix potential read of invalid memory in error
   handling (use stdcpy rather than sprintf to avoid
   read of non-existent argument if string contains a '%')




Modified: MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp	2009-10-20 01:55:29 UTC (rev 3225)
+++ MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp	2009-10-20 01:57:17 UTC (rev 3226)
@@ -15,6 +15,9 @@
 
 #include <iostream>
 #include <cassert>
+#include <cstring>
+#include <stdarg.h>
+#include <stdio.h>
 #define MIN(a,b) (a < b ? a : b)
 
 MBiMesh::MBiMesh()
@@ -195,10 +198,14 @@
   return reinterpret_cast<iMesh_EntityIterator>(iter);
 }
 
+static inline void
+iMesh_processError( iBase_ErrorType code, const char* desc ) 
+{
+  std::strncpy( iMesh_LAST_ERROR.description, desc,
+                sizeof(iMesh_LAST_ERROR.description) );
+  iMesh_LAST_ERROR.error_type = code;
+}
 
-
-#define iMesh_processError(a, b) {sprintf(iMesh_LAST_ERROR.description, "%s", b); iMesh_LAST_ERROR.error_type = a; *err = a;}
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -1631,7 +1638,7 @@
     static ::std::string name;
     MBErrorCode result = MBI->tag_get_name(TAG_HANDLE(tag_handle), name);
     if (MB_SUCCESS != result)
-      iMesh_processError(iBase_ERROR_MAP[result], "iMesh_getTagName: problem getting name.")
+      iMesh_processError(iBase_ERROR_MAP[result], "iMesh_getTagName: problem getting name.");
         else
           iMesh_LAST_ERROR.error_type = iBase_SUCCESS;
 
@@ -1667,7 +1674,7 @@
   {
     MBErrorCode result = MBI->tag_get_size(TAG_HANDLE(tag_handle), *tag_size_val);
     if (MB_SUCCESS != result)
-      iMesh_processError(iBase_ERROR_MAP[result], "iMesh_getTagSize: problem getting size.")
+      iMesh_processError(iBase_ERROR_MAP[result], "iMesh_getTagSize: problem getting size.");
         else {
           int this_type;
           int success;
@@ -1701,7 +1708,7 @@
   {
     MBErrorCode result = MBI->tag_get_size(TAG_HANDLE(tag_handle), *tag_size_bytes);
     if (MB_SUCCESS != result)
-      iMesh_processError(iBase_ERROR_MAP[result], "iMesh_getTagSize: problem getting size.")
+      iMesh_processError(iBase_ERROR_MAP[result], "iMesh_getTagSize: problem getting size.");
         else {
           iMesh_LAST_ERROR.error_type = iBase_SUCCESS;
         }



More information about the moab-dev mailing list