From 85e9e013abbb12dd22c477857aef38e73830ca1a Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 12 Apr 2012 13:24:48 +0200 Subject: [PATCH] 0000668: getPole() does not provide proper bound checking --- src/Mod/Part/App/BSplineCurvePyImp.cpp | 4 ++++ src/Mod/Part/App/BSplineSurfacePyImp.cpp | 6 ++++++ src/Mod/Part/App/BezierCurvePyImp.cpp | 4 ++++ src/Mod/Part/App/BezierSurfacePyImp.cpp | 21 +++++++++++++++++---- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Mod/Part/App/BSplineCurvePyImp.cpp b/src/Mod/Part/App/BSplineCurvePyImp.cpp index 91f103fa9..7f608c902 100644 --- a/src/Mod/Part/App/BSplineCurvePyImp.cpp +++ b/src/Mod/Part/App/BSplineCurvePyImp.cpp @@ -393,6 +393,8 @@ PyObject* BSplineCurvePy::getPole(PyObject * args) try { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles(), "Pole index out of range"); gp_Pnt pnt = curve->Pole(index); Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d( pnt.X(), pnt.Y(), pnt.Z())); @@ -457,6 +459,8 @@ PyObject* BSplineCurvePy::getWeight(PyObject * args) try { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles() , "Weight index out of range"); double weight = curve->Weight(index); return Py_BuildValue("d", weight); } diff --git a/src/Mod/Part/App/BSplineSurfacePyImp.cpp b/src/Mod/Part/App/BSplineSurfacePyImp.cpp index b16e78d9d..ed3e28d9f 100644 --- a/src/Mod/Part/App/BSplineSurfacePyImp.cpp +++ b/src/Mod/Part/App/BSplineSurfacePyImp.cpp @@ -751,6 +751,9 @@ PyObject* BSplineSurfacePy::getPole(PyObject *args) try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (uindex < 1 || uindex > surf->NbUPoles() || + vindex < 1 || vindex > surf->NbVPoles(), "Pole index out of range"); gp_Pnt pnt = surf->Pole(uindex,vindex); Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d( pnt.X(), pnt.Y(), pnt.Z())); @@ -870,6 +873,9 @@ PyObject* BSplineSurfacePy::getWeight(PyObject *args) try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (uindex < 1 || uindex > surf->NbUPoles() || + vindex < 1 || vindex > surf->NbVPoles(), "Weight index out of range"); double w = surf->Weight(uindex,vindex); return Py_BuildValue("d", w); } diff --git a/src/Mod/Part/App/BezierCurvePyImp.cpp b/src/Mod/Part/App/BezierCurvePyImp.cpp index f7653b50d..8acbb4bcc 100644 --- a/src/Mod/Part/App/BezierCurvePyImp.cpp +++ b/src/Mod/Part/App/BezierCurvePyImp.cpp @@ -231,6 +231,8 @@ PyObject* BezierCurvePy::getPole(PyObject * args) try { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles(), "Pole index out of range"); gp_Pnt pnt = curve->Pole(index); Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d( pnt.X(), pnt.Y(), pnt.Z())); @@ -321,6 +323,8 @@ PyObject* BezierCurvePy::getWeight(PyObject * args) try { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles() , "Weight index out of range"); double weight = curve->Weight(index); return Py_BuildValue("d", weight); } diff --git a/src/Mod/Part/App/BezierSurfacePyImp.cpp b/src/Mod/Part/App/BezierSurfacePyImp.cpp index 1554b27b0..6e9dea1be 100644 --- a/src/Mod/Part/App/BezierSurfacePyImp.cpp +++ b/src/Mod/Part/App/BezierSurfacePyImp.cpp @@ -190,10 +190,17 @@ PyObject* BezierSurfacePy::increase(PyObject *args) int udegree,vdegree; if (!PyArg_ParseTuple(args, "ii", &udegree, &vdegree)) return 0; - Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast - (getGeometryPtr()->handle()); - surf->Increase(udegree, vdegree); - Py_Return; + try { + Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast + (getGeometryPtr()->handle()); + surf->Increase(udegree, vdegree); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } } PyObject* BezierSurfacePy::insertPoleColAfter(PyObject *args) @@ -528,6 +535,9 @@ PyObject* BezierSurfacePy::getPole(PyObject *args) try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (uindex < 1 || uindex > surf->NbUPoles() || + vindex < 1 || vindex > surf->NbVPoles(), "Pole index out of range"); gp_Pnt p = surf->Pole(uindex,vindex); return new Base::VectorPy(Base::Vector3d(p.X(),p.Y(),p.Z())); } @@ -645,6 +655,9 @@ PyObject* BezierSurfacePy::getWeight(PyObject *args) try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (uindex < 1 || uindex > surf->NbUPoles() || + vindex < 1 || vindex > surf->NbVPoles(), "Weight index out of range"); double w = surf->Weight(uindex,vindex); return Py_BuildValue("d", w); }