View Issue Details

IDProjectCategoryView StatusLast Update
0026377Open CASCADEOCCT:Foundation Classespublic2016-04-20 15:51
ReporterabvAssigned Toabv 
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Target Version7.0.0Fixed in Version7.0.0 
Summary0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous
DescriptionAs pointed out by Roman Lygin, passing Handle object as argument to function accepting non-const reference to handle to base type may be dangerous, as the handle can be modified by that function, and there is no guarantee that the new object pointed by it will be compatible with the original handle type.

Example:

  Handle(TDataStd_Real) A;
  if (Label.FindAttribute (TDataStd_Integer::GetID(), A)) {
    // A is used as TData_Std_Real, while the object pointed by it is TDataStd_Integer
  }

It would be good to have protection in this situation, to ensure that either exception is raised or at least handle is nullified if it is assigned non-compatible type. This should be possible when new handles are implemented in the frames of 0024023
Steps To ReproduceNot required
TagsNo tags attached.
Test case number

Relationships

related to 0024023 closedabv Open CASCADE Revamp the OCCT Handle 
related to 0027104 closedabv Community DownCast() cannot return null for mismatched handle 
related to 0027111 closedabv Community Add generalized copy constructor in handle class for old compilers 
related to 0027185 closedbugmaster Open CASCADE Data Exchange - IGES - incorrect reading of DE for undefined entity 

Activities

git

2015-06-29 07:08

administrator   ~0042518

Branch CR26377 has been created by abv.

SHA-1: 87f01da0abf201904b5ae6b1c06b98492aa94ad9


Detailed log of new commits:

Author: abv
Date: Sun Jun 28 13:52:12 2015 +0300

    0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous
    
    Function SafeUpCast() added in opencascade::handle class to allow safe passing of handle as argument to functions accepting non-const reference to handle of base type.
    Operator of cast to non-const reference is removed.

bugmaster

2016-02-19 11:03

administrator   ~0050997

Tested with CR26711_6

git

2016-04-17 15:06

administrator   ~0053250

Branch CR26377 has been deleted by kgv.

SHA-1: 87f01da0abf201904b5ae6b1c06b98492aa94ad9

Related Changesets

occt: master aa00364d

2016-02-17 14:33:18

abv


Committer: abv Details Diff
0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous

Operator of cast to non-const reference is declared deprecated to produce compiler warning if used (usually implicitly).

OCCT code is updated to avoid that cast, occurring when function accepting non-const reference to handle is called with handle to derived type.
For that, local variable of argument type is passed instead, and down-cast is used to get it to desired type after the call.
A few occurrences of use of uninitialized variable are corrected.
Affected Issues
0026377
mod - src/AIS/AIS_AngleDimension.cxx Diff File
mod - src/AIS/AIS_Chamf2dDimension.cxx Diff File
mod - src/AIS/AIS_SymmetricRelation.cxx Diff File
mod - src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx Diff File
mod - src/BinDrivers/BinDrivers_DocumentStorageDriver.cxx Diff File
mod - src/BinMXCAFDoc/BinMXCAFDoc.cxx Diff File
mod - src/DDF/DDF.hxx Diff File
mod - src/DDocStd/DDocStd.hxx Diff File
mod - src/Dico/Dico_DictionaryOfTransient.hxx Diff File
mod - src/DrawTrSurf/DrawTrSurf.cxx Diff File
mod - src/GeomTools/GeomTools.cxx Diff File
mod - src/GeomTools/GeomTools_Curve2dSet.cxx Diff File
mod - src/GeomTools/GeomTools_Curve2dSet.hxx Diff File
mod - src/GeomTools/GeomTools_CurveSet.cxx Diff File
mod - src/GeomTools/GeomTools_CurveSet.hxx Diff File
mod - src/GeomTools/GeomTools_SurfaceSet.cxx Diff File
mod - src/GeomTools/GeomTools_SurfaceSet.hxx Diff File
mod - src/IFSelect/IFSelect_Activator.cxx Diff File
mod - src/IGESData/IGESData_BasicEditor.cxx Diff File
mod - src/IGESData/IGESData_FreeFormatEntity.cxx Diff File
mod - src/IGESData/IGESData_IGESReaderTool.cxx Diff File
mod - src/IGESData/IGESData_ParamReader.cxx Diff File
mod - src/IGESData/IGESData_ParamReader.hxx Diff File
mod - src/IGESData/IGESData_ToolLocation.cxx Diff File
mod - src/IGESDraw/IGESDraw_ToolViewsVisible.cxx Diff File
mod - src/IGESDraw/IGESDraw_ToolViewsVisibleWithAttr.cxx Diff File
mod - src/IGESGeom/IGESGeom_ToolBoundedSurface.cxx Diff File
mod - src/IGESSelect/IGESSelect_RebuildDrawings.cxx Diff File
mod - src/IGESSolid/IGESSolid_ToolManifoldSolid.cxx Diff File
mod - src/IGESSolid/IGESSolid_ToolToroidalSurface.cxx Diff File
mod - src/Interface/Interface_CopyTool.cxx Diff File
mod - src/IntTools/IntTools_FaceFace.cxx Diff File
mod - src/MoniTool/MoniTool_Profile.cxx Diff File
mod - src/OpenGl/OpenGl_Context.cxx Diff File
mod - src/OpenGl/OpenGl_Context.hxx Diff File
mod - src/OpenGl/OpenGl_View_Raytrace.cxx Diff File
mod - src/PrsMgr/PrsMgr_PresentationManager.cxx Diff File
mod - src/QANCollection/QANCollection_Handle.cxx Diff File
mod - src/Select3D/Select3D_SensitiveGroup.cxx Diff File
mod - src/Standard/Standard_Handle.hxx Diff File
mod - src/StdObjMgt/StdObjMgt_ReadData.hxx Diff File
mod - src/STEPCAFControl/STEPCAFControl_Writer.cxx Diff File
mod - src/StepData/StepData_StepReaderData.cxx Diff File
mod - src/StepData/StepData_StepReaderData.hxx Diff File
mod - src/StepData/StepData_StepReaderTool.cxx Diff File
mod - src/TDF/TDF_Attribute.hxx Diff File
mod - src/TDF/TDF_Label.hxx Diff File
mod - src/TDF/TDF_RelocationTable.hxx Diff File
mod - src/TNaming/TNaming_NamedShape.cxx Diff File
mod - src/TPrsStd/TPrsStd_ConstraintTools.cxx Diff File
mod - src/Transfer/Transfer_ProcessForFinder.hxx Diff File
mod - src/VrmlData/VrmlData_IndexedFaceSet.cxx Diff File
mod - src/VrmlData/VrmlData_IndexedLineSet.cxx Diff File
mod - src/VrmlData/VrmlData_Node.cxx Diff File
mod - src/XmlDrivers/XmlDrivers_DocumentRetrievalDriver.cxx Diff File
mod - src/XmlDrivers/XmlDrivers_DocumentStorageDriver.cxx Diff File
mod - src/XmlMXCAFDoc/XmlMXCAFDoc.cxx Diff File
mod - tests/de/iges_2/F9 Diff File
mod - tests/perf/fclasses/handle Diff File

Issue History

Date Modified Username Field Change
2015-06-28 13:46 abv New Issue
2015-06-28 13:46 abv Assigned To => abv
2015-06-28 13:57 abv Relationship added related to 0024023
2015-06-29 07:08 git Note Added: 0042518
2015-12-14 22:39 abv Target Version 7.0.0 => 7.1.0
2016-01-21 16:30 Roman Lygin Relationship added related to 0026497
2016-01-21 16:31 Roman Lygin Relationship deleted related to 0026497
2016-01-21 16:31 Roman Lygin Relationship added related to 0027104
2016-01-25 20:36 Roman Lygin Relationship added related to 0027111
2016-02-18 19:00 abv Relationship added related to 0027185
2016-02-19 11:02 bugmaster Status new => resolved
2016-02-19 11:02 bugmaster Steps to Reproduce Updated
2016-02-19 11:02 bugmaster Steps to Reproduce Updated
2016-02-19 11:03 bugmaster Assigned To abv => bugmaster
2016-02-19 11:03 bugmaster Status resolved => reviewed
2016-02-19 11:03 bugmaster Note Added: 0050997
2016-02-19 11:03 bugmaster Status reviewed => tested
2016-02-19 11:21 abv Target Version 7.1.0 => 7.0.0
2016-02-21 08:52 abv Changeset attached => occt master aa00364d
2016-02-21 08:52 abv Assigned To bugmaster => abv
2016-02-21 08:52 abv Status tested => verified
2016-02-21 08:52 abv Resolution open => fixed
2016-04-17 15:06 git Note Added: 0053250
2016-04-20 15:42 aiv Fixed in Version => 7.0.0
2016-04-20 15:51 aiv Status verified => closed