mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0017100: [OCC Forum] Buffer overflow vulnerability and loading TKOpenGl without environment variables on unix systems
This commit is contained in:
@@ -20,7 +20,8 @@ uses
|
||||
GraphicDriver from Aspect,
|
||||
Display from Aspect,
|
||||
GraphicDriver from Graphic3d,
|
||||
TypeOfMapping from Xw
|
||||
TypeOfMapping from Xw,
|
||||
AsciiString from TCollection
|
||||
|
||||
raises
|
||||
|
||||
@@ -62,14 +63,14 @@ is
|
||||
---Level: Internal
|
||||
---Purpose: Sets the GraphicDriver.
|
||||
|
||||
ShrIsDefined ( me;
|
||||
aShr : out CString from Standard )
|
||||
returns Boolean from Standard
|
||||
ShrEnvString ( me )
|
||||
returns AsciiString from TCollection
|
||||
is private;
|
||||
---Level: Internal
|
||||
---Purpose: Returns Standard_True if the shared library
|
||||
-- is defined by the environment.
|
||||
-- (variables : CSF_GraphicShr, CSF_Graphic3dLib, GRAPHICHOME)
|
||||
---Purpose: Returns the environment string for loading shared graphics library.
|
||||
-- The string can be defined in environment by corresponding variables,
|
||||
-- or default value will be used for loading from system library path
|
||||
-- Environment variables : CSF_GraphicShr
|
||||
|
||||
fields
|
||||
|
||||
|
@@ -14,12 +14,7 @@
|
||||
is loading from the current PATH
|
||||
|
||||
************************************************************************/
|
||||
#define RIC120302 //GG Add new constructor to pass Display structure
|
||||
// directly instead string connexion.
|
||||
|
||||
#define XDESTROY
|
||||
|
||||
#ifndef WNT
|
||||
#if (!defined(_WIN32) && !defined(__WIN32__))
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/utsname.h>
|
||||
@@ -32,6 +27,7 @@
|
||||
#include <Graphic3d_GraphicDevice.ixx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
#include <OSD_Function.hxx>
|
||||
#include <OSD_Environment.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
#include <Xw_Cextern.hxx>
|
||||
@@ -73,7 +69,6 @@ Standard_Boolean status ;
|
||||
|
||||
}
|
||||
|
||||
//RIC120302
|
||||
Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Aspect_Display pdisplay)
|
||||
: Xw_GraphicDevice ()
|
||||
{
|
||||
@@ -104,18 +99,11 @@ Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Aspect_Display pdisplay)
|
||||
|
||||
this->InitMaps (connexion,Xw_TOM_READONLY,0,Standard_True);
|
||||
}
|
||||
//RIC120302
|
||||
|
||||
// Destructor
|
||||
|
||||
void Graphic3d_GraphicDevice::Destroy () {
|
||||
|
||||
#ifdef DESTROY
|
||||
cout << "Graphic3d_GraphicDevice::Destroy ()\n";
|
||||
#endif
|
||||
|
||||
MyGraphicDriver->End ();
|
||||
|
||||
void Graphic3d_GraphicDevice::Destroy()
|
||||
{
|
||||
MyGraphicDriver->End();
|
||||
}
|
||||
|
||||
// Methods in order
|
||||
@@ -128,16 +116,11 @@ Handle(Aspect_GraphicDriver) Graphic3d_GraphicDevice::GraphicDriver () const {
|
||||
|
||||
void Graphic3d_GraphicDevice::SetGraphicDriver () {
|
||||
|
||||
Standard_CString TheShr;
|
||||
TCollection_AsciiString aShr = ShrEnvString ();
|
||||
|
||||
if (! ShrIsDefined (TheShr)) {
|
||||
Aspect_GraphicDeviceDefinitionError::Raise
|
||||
("Bad environment, Graphic Library not defined");
|
||||
}
|
||||
OSD_SharedLibrary TheSharedLibrary (aShr.ToCString());
|
||||
|
||||
OSD_SharedLibrary TheSharedLibrary (TheShr);
|
||||
|
||||
Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY);
|
||||
Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY);
|
||||
|
||||
if (! Result) {
|
||||
Aspect_GraphicDeviceDefinitionError::Raise
|
||||
@@ -148,7 +131,7 @@ Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY);
|
||||
char *tracevalue = NULL;
|
||||
tracevalue = (char *)(getenv ("CSF_GraphicTrace"));
|
||||
if (tracevalue)
|
||||
cout << "Information : " << TheShr << " loaded\n" << flush;
|
||||
cout << "Information : " << aShr << " loaded\n" << flush;
|
||||
|
||||
OSD_Function new_GLGraphicDriver =
|
||||
TheSharedLibrary.DlSymb ("MetaGraphicDriverFactory");
|
||||
@@ -183,46 +166,22 @@ OSD_Function new_GLGraphicDriver =
|
||||
|
||||
}
|
||||
|
||||
#define BAD(x) (((x) == NULL) || (strlen((x)) <= 0))
|
||||
|
||||
Standard_Boolean Graphic3d_GraphicDevice::ShrIsDefined (Standard_CString& aShr) const {
|
||||
|
||||
char *glso, *glul, *pkno;
|
||||
char *glshr, *casroot;
|
||||
|
||||
casroot = getenv("CASROOT");
|
||||
glso = getenv("CSF_GraphicShr");
|
||||
glul = getenv("GRAPHICHOME");
|
||||
pkno = getenv("CSF_Graphic3dLib");
|
||||
|
||||
if (! BAD(glso)) {
|
||||
glshr = getenv("CSF_GraphicShr");
|
||||
} else if (! BAD(casroot)) {
|
||||
TCollection_AsciiString buffString(casroot);
|
||||
struct utsname info;
|
||||
uname (&info);
|
||||
buffString = buffString + "/";
|
||||
buffString = buffString + info.sysname;
|
||||
#if defined(__hpux) || defined(HPUX)
|
||||
buffString = buffString + "/lib/libTKOpenGl.sl";
|
||||
#elif defined(WNT)
|
||||
buffString = buffString + "/TKOpenGl.dll";
|
||||
#elif defined(__APPLE__)
|
||||
buffString = buffString + "/lib/libTKOpenGl.dylib";
|
||||
#else
|
||||
buffString = buffString + "/lib/libTKOpenGl.so";
|
||||
#endif
|
||||
glshr = (char *) malloc (buffString.Length() + 1);
|
||||
memcpy(glshr, buffString.ToCString(), buffString.Length() + 1);
|
||||
} else {
|
||||
aShr = NULL;
|
||||
printf("You have not defined CSF_GraphicShr or CASROOT, aborting...");
|
||||
return Standard_False;
|
||||
TCollection_AsciiString Graphic3d_GraphicDevice::ShrEnvString() const
|
||||
{
|
||||
OSD_Environment aEnvShr ("CSF_GraphicShr");
|
||||
if (!aEnvShr.Value().IsEmpty())
|
||||
{
|
||||
return aEnvShr.Value();
|
||||
}
|
||||
|
||||
aShr = glshr;
|
||||
|
||||
return Standard_True;
|
||||
|
||||
|
||||
// load TKOpenGl using default searching mechanisms in system
|
||||
#if defined(__hpux) || defined(HPUX)
|
||||
return TCollection_AsciiString ("libTKOpenGl.sl");
|
||||
#elif defined(__APPLE__)
|
||||
return TCollection_AsciiString ("libTKOpenGl.dylib");
|
||||
#else
|
||||
return TCollection_AsciiString ("libTKOpenGl.so");
|
||||
#endif
|
||||
}
|
||||
#endif // WNT
|
||||
|
||||
#endif // !WNT
|
||||
|
Reference in New Issue
Block a user