|
|
03f605 |
From 61f79b8447c3ac8ab5a26e79e0c28053ffdccf75 Mon Sep 17 00:00:00 2001
|
|
|
03f605 |
From: Albert Astals Cid <aacid@kde.org>
|
|
|
03f605 |
Date: Wed, 23 Oct 2013 22:54:56 +0000
|
|
|
03f605 |
Subject: Allow only one %d in the filename
|
|
|
03f605 |
|
|
|
03f605 |
Fixes crashes if you had %s and similar in the filename
|
|
|
03f605 |
|
|
|
03f605 |
Inspired from patch by Pedro Ribeiro <pedrib@gmail.com>
|
|
|
03f605 |
|
|
|
03f605 |
Bug #69434
|
|
|
03f605 |
---
|
|
|
03f605 |
diff --git a/utils/pdfseparate.cc b/utils/pdfseparate.cc
|
|
|
03f605 |
index 1d4901b..6424d20 100644
|
|
|
03f605 |
--- a/utils/pdfseparate.cc
|
|
|
03f605 |
+++ b/utils/pdfseparate.cc
|
|
|
03f605 |
@@ -20,6 +20,7 @@
|
|
|
03f605 |
#include "PDFDoc.h"
|
|
|
03f605 |
#include "ErrorCodes.h"
|
|
|
03f605 |
#include "GlobalParams.h"
|
|
|
03f605 |
+#include <ctype.h>
|
|
|
03f605 |
|
|
|
03f605 |
static int firstPage = 0;
|
|
|
03f605 |
static int lastPage = 0;
|
|
|
03f605 |
@@ -63,9 +64,37 @@ bool extractPages (const char *srcFileName, const char *destFileName) {
|
|
|
03f605 |
if (firstPage == 0)
|
|
|
03f605 |
firstPage = 1;
|
|
|
03f605 |
if (firstPage != lastPage && strstr(destFileName, "%d") == NULL) {
|
|
|
03f605 |
- error(errSyntaxError, -1, "'{0:s}' must contain '%%d' if more than one page should be extracted", destFileName);
|
|
|
03f605 |
+ error(errSyntaxError, -1, "'{0:s}' must contain '%d' if more than one page should be extracted", destFileName);
|
|
|
03f605 |
return false;
|
|
|
03f605 |
}
|
|
|
03f605 |
+
|
|
|
03f605 |
+ // destFileName can have multiple %% and one %d
|
|
|
03f605 |
+ // We use auxDestFileName to replace all the valid % appearances
|
|
|
03f605 |
+ // by 'A' (random char that is not %), if at the end of replacing
|
|
|
03f605 |
+ // any of the valid appearances there is still any % around, the
|
|
|
03f605 |
+ // pattern is wrong
|
|
|
03f605 |
+ char *auxDestFileName = strdup(destFileName);
|
|
|
03f605 |
+ // %% can appear as many times as you want
|
|
|
03f605 |
+ char *p = strstr(auxDestFileName, "%%");
|
|
|
03f605 |
+ while (p != NULL) {
|
|
|
03f605 |
+ *p = 'A';
|
|
|
03f605 |
+ *(p + 1) = 'A';
|
|
|
03f605 |
+ p = strstr(p, "%%");
|
|
|
03f605 |
+ }
|
|
|
03f605 |
+ // %d can appear only one time
|
|
|
03f605 |
+ p = strstr(auxDestFileName, "%d");
|
|
|
03f605 |
+ if (p != NULL) {
|
|
|
03f605 |
+ *p = 'A';
|
|
|
03f605 |
+ }
|
|
|
03f605 |
+ // at this point any other % is wrong
|
|
|
03f605 |
+ p = strstr(auxDestFileName, "%");
|
|
|
03f605 |
+ if (p != NULL) {
|
|
|
03f605 |
+ error(errSyntaxError, -1, "'{0:s}' can only contain one '%d' pattern", destFileName);
|
|
|
03f605 |
+ free(auxDestFileName);
|
|
|
03f605 |
+ return false;
|
|
|
03f605 |
+ }
|
|
|
03f605 |
+ free(auxDestFileName);
|
|
|
03f605 |
+
|
|
|
03f605 |
for (int pageNo = firstPage; pageNo <= lastPage; pageNo++) {
|
|
|
03f605 |
snprintf (pathName, sizeof (pathName) - 1, destFileName, pageNo);
|
|
|
03f605 |
GooString *gpageName = new GooString (pathName);
|
|
|
03f605 |
--
|
|
|
03f605 |
cgit v0.9.0.2-2-gbebe
|