From 1429966f97e1425f068a42fe9b4f96d3294d225a Mon Sep 17 00:00:00 2001 From: cth103 Date: Mon, 23 Jan 2006 14:19:27 +0000 Subject: [PATCH] Catch failures in fopen of XML files. Fixes #1374551. --- ChangeLog | 3 +++ src/xml/repr-io.cpp | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d856ba05b..18df22f3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ * src/selection.cpp: fix a typo in one of my previous commits. Closes #1401357. + * src/xml/repr-io.cpp: catch failures in fopen of XML files. + Closes #1374551. + 2006-01-20 Michael Wybrow * src/widgets/toolbox.cpp, src/widgets/desktop-widget.cpp, diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 02aca4dc6..bb62393fc 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -16,7 +16,7 @@ # include #endif - +#include #include "xml/repr.h" #include "xml/attribute-record.h" @@ -80,9 +80,13 @@ private: Inkscape::IO::GzipInputStream* gzin; }; -void XmlSource::setFile( char const * filename ) { +void XmlSource::setFile(char const *filename) +{ this->filename = filename; fp = Inkscape::IO::fopen_utf8name(filename, "r"); + if (fp == NULL) { + throw std::runtime_error("Could not open file for reading"); + } first = true; } @@ -214,7 +218,14 @@ sp_repr_read_file (const gchar * filename, const gchar *default_ns) Inkscape::IO::dump_fopen_call( filename, "N" ); XmlSource src; - src.setFile(filename); + try + { + src.setFile(filename); + } + catch (...) + { + return NULL; + } xmlDocPtr doubleDoc = xmlReadIO( XmlSource::readCb, XmlSource::closeCb, -- 2.30.2