fix further file names vulnerabilities in TechDraw module

This commit is contained in:
wmayer
2019-10-03 02:45:38 +02:00
parent 21f59ecb67
commit 2134086d4c
5 changed files with 45 additions and 18 deletions

View File

@@ -30,6 +30,7 @@
#include <vector>
#include <Base/Tools.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
@@ -201,6 +202,7 @@ void CmdTechDrawNewPage::activated(int iMsg)
//why is "Template" property set twice? -wf
// once to set DrawSVGTemplate.Template to OS template file name
templateFileName = Base::Tools::escapeEncodeFilename(templateFileName);
doCommand(Doc,"App.activeDocument().%s.Template = \"%s\"",TemplateName.c_str(), templateFileName.toUtf8().constData());
// once to set Page.Template to DrawSVGTemplate.Name
doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str());
@@ -974,6 +976,7 @@ void CmdTechDrawSymbol::activated(int iMsg)
if (!filename.isEmpty())
{
std::string FeatName = getUniqueObjectName("Symbol");
filename = Base::Tools::escapeEncodeFilename(filename);
openCommand("Create Symbol");
#if PY_MAJOR_VERSION < 3
doCommand(Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)filename.toUtf8());
@@ -1256,6 +1259,7 @@ void CmdTechDrawExportPageDxf::activated(int iMsg)
std::string PageName = page->getNameInDocument();
openCommand("Save page to dxf");
doCommand(Doc,"import TechDraw");
fileName = Base::Tools::escapeEncodeFilename(fileName);
doCommand(Doc,"TechDraw.writeDXFPage(App.activeDocument().%s,u\"%s\")",PageName.c_str(),(const char*)fileName.toUtf8());
commitCommand();
}

View File

@@ -32,6 +32,7 @@
#include <QGraphicsView>
# include <Base/Tools.h>
# include <App/DocumentObject.h>
# include <Gui/Action.h>
# include <Gui/Application.h>
@@ -408,6 +409,7 @@ void CmdTechDrawImage::activated(int iMsg)
if (!fileName.isEmpty())
{
std::string FeatName = getUniqueObjectName("Image");
fileName = Base::Tools::escapeEncodeFilename(fileName);
openCommand("Create Image");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewImage','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.ImageFile = '%s'",FeatName.c_str(),fileName.toUtf8().constData());

View File

@@ -49,6 +49,7 @@
#include "MDIViewPage.h"
#include <Base/Stream.h>
#include <Base/Tools.h>
#include <Base/gzstream.h>
#include <Base/PyObjectBase.h>
#include <Base/Console.h>
@@ -924,6 +925,7 @@ void MDIViewPage::saveDXF(std::string fileName)
{
TechDraw::DrawPage* page = m_vpPage->getDrawPage();
std::string PageName = page->getNameInDocument();
fileName = Base::Tools::escapeEncodeFilename(fileName);
Gui::Command::openCommand("Save page to dxf");
Gui::Command::doCommand(Gui::Command::Doc,"import TechDraw");
Gui::Command::doCommand(Gui::Command::Doc,"TechDraw.writeDXFPage(App.activeDocument().%s,u\"%s\")",

View File

@@ -135,6 +135,7 @@ TechDraw::DrawViewSymbol* TaskActiveView::createActiveView(void)
tempFile.close();
std::string fileSpec = Base::Tools::toStdString(tempFile.fileName());
fileSpec = Base::Tools::escapeEncodeFilename(fileSpec);
//double estScale =
Grabber3d::copyActiveViewToSvgFile(appDoc, fileSpec,

View File

@@ -447,6 +447,7 @@ TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void)
symbolName.c_str(), altWeldText.c_str());
std::string tailText = Base::Tools::toStdString(ui->leTailText->text());
tailText = Base::Tools::escapeEncodeString(tailText);
Command::doCommand(Command::Doc,"App.activeDocument().%s.TailText = '%s'",
symbolName.c_str(), tailText.c_str());
@@ -481,6 +482,7 @@ void TaskWeldingSymbol::updateWeldingSymbol(void)
symbolName.c_str(), altWeldText.c_str());
std::string tailText = Base::Tools::toStdString(ui->leTailText->text());
tailText = Base::Tools::escapeEncodeString(tailText);
Command::doCommand(Command::Doc,"App.activeDocument().%s.TailText = '%s'",
symbolName.c_str(), tailText.c_str());
}
@@ -490,10 +492,14 @@ std::vector<App::DocumentObject*> TaskWeldingSymbol::createTiles(void)
// Base::Console().Message("TWS::createTiles()\n");
std::vector<App::DocumentObject*> tileFeats;
std::string tileType("TechDraw::DrawTileWeld");
collectArrowData();
if (m_arrowOut.toBeSaved) {
std::string tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld");
std::string symbolPath = Base::Tools::escapeEncodeString(m_arrowOut.symbolPath);
std::string leftText = Base::Tools::escapeEncodeString(m_arrowOut.leftText);
std::string rightText = Base::Tools::escapeEncodeString(m_arrowOut.rightText);
std::string centerText = Base::Tools::escapeEncodeString(m_arrowOut.centerText);
Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')",
tileType.c_str(),tileName.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d",
@@ -501,13 +507,13 @@ std::vector<App::DocumentObject*> TaskWeldingSymbol::createTiles(void)
Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d",
tileName.c_str(), m_arrowOut.col);
Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'",
tileName.c_str(), m_arrowOut.symbolPath.c_str());
tileName.c_str(), symbolPath.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'",
tileName.c_str(), m_arrowOut.leftText.c_str());
tileName.c_str(), leftText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'",
tileName.c_str(), m_arrowOut.rightText.c_str());
tileName.c_str(), rightText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'",
tileName.c_str(), m_arrowOut.centerText.c_str());
tileName.c_str(), centerText.c_str());
App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str());
if (newTile == nullptr) {
throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found");
@@ -530,16 +536,20 @@ std::vector<App::DocumentObject*> TaskWeldingSymbol::createTiles(void)
Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''",
tileName.c_str());
} else {
std::string symbolPath = Base::Tools::escapeEncodeString(m_otherOut.symbolPath);
Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'",
tileName.c_str(), m_otherOut.symbolPath.c_str());
tileName.c_str(), symbolPath.c_str());
}
std::string leftText = Base::Tools::escapeEncodeString(m_otherOut.leftText);
std::string rightText = Base::Tools::escapeEncodeString(m_otherOut.rightText);
std::string centerText = Base::Tools::escapeEncodeString(m_otherOut.centerText);
Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'",
tileName.c_str(), m_otherOut.leftText.c_str());
tileName.c_str(), leftText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'",
tileName.c_str(), m_otherOut.rightText.c_str());
tileName.c_str(), rightText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'",
tileName.c_str(), m_otherOut.centerText.c_str());
tileName.c_str(), centerText.c_str());
App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str());
if (newTile == nullptr) {
throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found");
@@ -584,16 +594,20 @@ std::vector<App::DocumentObject*> TaskWeldingSymbol::updateTiles(void)
Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''",
tileName.c_str());
} else {
std::string symbolPath = Base::Tools::escapeEncodeString(m_arrowOut.symbolPath);
Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'",
tileName.c_str(), m_arrowOut.symbolPath.c_str());
tileName.c_str(), symbolPath.c_str());
}
std::string leftText = Base::Tools::escapeEncodeString(m_arrowOut.leftText);
std::string rightText = Base::Tools::escapeEncodeString(m_arrowOut.rightText);
std::string centerText = Base::Tools::escapeEncodeString(m_arrowOut.centerText);
Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'",
tileName.c_str(), m_arrowOut.leftText.c_str());
tileName.c_str(), leftText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'",
tileName.c_str(), m_arrowOut.rightText.c_str());
tileName.c_str(), rightText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'",
tileName.c_str(), m_arrowOut.centerText.c_str());
tileName.c_str(), centerText.c_str());
}
if (m_otherDirty) {
@@ -627,16 +641,20 @@ std::vector<App::DocumentObject*> TaskWeldingSymbol::updateTiles(void)
Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''",
tileName.c_str());
} else {
std::string symbolPath = Base::Tools::escapeEncodeString(m_otherOut.symbolPath);
Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'",
tileName.c_str(), m_otherOut.symbolPath.c_str());
tileName.c_str(), symbolPath.c_str());
}
std::string leftText = Base::Tools::escapeEncodeString(m_otherOut.leftText);
std::string rightText = Base::Tools::escapeEncodeString(m_otherOut.rightText);
std::string centerText = Base::Tools::escapeEncodeString(m_otherOut.centerText);
Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'",
tileName.c_str(), m_otherOut.leftText.c_str());
tileName.c_str(), leftText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'",
tileName.c_str(), m_otherOut.rightText.c_str());
tileName.c_str(), rightText.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'",
tileName.c_str(), m_otherOut.centerText.c_str());
tileName.c_str(), centerText.c_str());
}
}