summaryrefslogtreecommitdiff
authorAlbert Astals Cid <aacid@kde.org>2013-10-23 22:54:56 (GMT)
committer Albert Astals Cid <aacid@kde.org>2013-10-23 22:54:56 (GMT)
commit61f79b8447c3ac8ab5a26e79e0c28053ffdccf75 (patch) (side-by-side diff)
tree754edd31ffff5662ac0150e7a73e7dbe9326d1ae
parentdaa0990a7baf17d00d12574a4de815e070727a86 (diff)
downloadpoppler-61f79b8447c3ac8ab5a26e79e0c28053ffdccf75.zip
poppler-61f79b8447c3ac8ab5a26e79e0c28053ffdccf75.tar.gz
Allow only one %d in the filename
Fixes crashes if you had %s and similar in the filename Inspired from patch by Pedro Ribeiro <pedrib@gmail.com> Bug #69434
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--utils/pdfseparate.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/utils/pdfseparate.cc b/utils/pdfseparate.cc
index 1d4901b..6424d20 100644
--- a/utils/pdfseparate.cc
+++ b/utils/pdfseparate.cc
@@ -20,6 +20,7 @@
#include "PDFDoc.h"
#include "ErrorCodes.h"
#include "GlobalParams.h"
+#include <ctype.h>
static int firstPage = 0;
static int lastPage = 0;
@@ -63,9 +64,37 @@ bool extractPages (const char *srcFileName, const char *destFileName) {
if (firstPage == 0)
firstPage = 1;
if (firstPage != lastPage && strstr(destFileName, "%d") == NULL) {
- error(errSyntaxError, -1, "'{0:s}' must contain '%%d' if more than one page should be extracted", destFileName);
+ error(errSyntaxError, -1, "'{0:s}' must contain '%d' if more than one page should be extracted", destFileName);
return false;
}
+
+ // destFileName can have multiple %% and one %d
+ // We use auxDestFileName to replace all the valid % appearances
+ // by 'A' (random char that is not %), if at the end of replacing
+ // any of the valid appearances there is still any % around, the
+ // pattern is wrong
+ char *auxDestFileName = strdup(destFileName);
+ // %% can appear as many times as you want
+ char *p = strstr(auxDestFileName, "%%");
+ while (p != NULL) {
+ *p = 'A';
+ *(p + 1) = 'A';
+ p = strstr(p, "%%");
+ }
+ // %d can appear only one time
+ p = strstr(auxDestFileName, "%d");
+ if (p != NULL) {
+ *p = 'A';
+ }
+ // at this point any other % is wrong
+ p = strstr(auxDestFileName, "%");
+ if (p != NULL) {
+ error(errSyntaxError, -1, "'{0:s}' can only contain one '%d' pattern", destFileName);
+ free(auxDestFileName);
+ return false;
+ }
+ free(auxDestFileName);
+
for (int pageNo = firstPage; pageNo <= lastPage; pageNo++) {
snprintf (pathName, sizeof (pathName) - 1, destFileName, pageNo);
GooString *gpageName = new GooString (pathName);