summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Kasik <mkasik@redhat.com>2012-12-09 20:20:00 +0100
committerAlbert Astals Cid <aacid@kde.org>2012-12-09 20:20:00 +0100
commit71bad47ed6a36d825b0d08992c8db56845c71e40 (patch)
tree1ab431b3af6bddf678fc93fbbaed6499ca34ac3d
parentc35d030472e6cb140c3dff30b91541772c992eb0 (diff)
Filter stuff that might end up in the shell
Since it seems shells don't know how to filter stuff and might causing bad things to happen
-rw-r--r--poppler/Error.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/poppler/Error.cc b/poppler/Error.cc
index 9d044bc7..ce71820b 100644
--- a/poppler/Error.cc
+++ b/poppler/Error.cc
@@ -16,6 +16,7 @@
16// Copyright (C) 2005, 2007 Jeff Muizelaar <jeff@infidigm.net> 16// Copyright (C) 2005, 2007 Jeff Muizelaar <jeff@infidigm.net>
17// Copyright (C) 2005 Albert Astals Cid <aacid@kde.org> 17// Copyright (C) 2005 Albert Astals Cid <aacid@kde.org>
18// Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com> 18// Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
19// Copyright (C) 2012 Marek Kasik <mkasik@redhat.com>
19// 20//
20// To see a description of the changes please see the Changelog file that 21// To see a description of the changes please see the Changelog file that
21// came with your tarball or type make ChangeLog if you are building from git 22// came with your tarball or type make ChangeLog if you are building from git
@@ -59,7 +60,7 @@ void setErrorCallback(void (*cbk)(void *data, ErrorCategory category,
59 60
60void CDECL error(ErrorCategory category, int pos, const char *msg, ...) { 61void CDECL error(ErrorCategory category, int pos, const char *msg, ...) {
61 va_list args; 62 va_list args;
62 GooString *s; 63 GooString *s, *sanitized;
63 64
64 // NB: this can be called before the globalParams object is created 65 // NB: this can be called before the globalParams object is created
65 if (!errorCbk && globalParams && globalParams->getErrQuiet()) { 66 if (!errorCbk && globalParams && globalParams->getErrQuiet()) {
@@ -68,17 +69,29 @@ void CDECL error(ErrorCategory category, int pos, const char *msg, ...) {
68 va_start(args, msg); 69 va_start(args, msg);
69 s = GooString::formatv(msg, args); 70 s = GooString::formatv(msg, args);
70 va_end(args); 71 va_end(args);
72
73 sanitized = new GooString ();
74 for (int i = 0; i < s->getLength(); ++i) {
75 const char c = s->getChar(i);
76 if (c < (char)0x20 || c >= (char)0x7f) {
77 sanitized->appendf("<{0:02x}>", c & 0xff);
78 } else {
79 sanitized->append(c);
80 }
81 }
82
71 if (errorCbk) { 83 if (errorCbk) {
72 (*errorCbk)(errorCbkData, category, pos, s->getCString()); 84 (*errorCbk)(errorCbkData, category, pos, sanitized->getCString());
73 } else { 85 } else {
74 if (pos >= 0) { 86 if (pos >= 0) {
75 fprintf(stderr, "%s (%d): %s\n", 87 fprintf(stderr, "%s (%d): %s\n",
76 errorCategoryNames[category], pos, s->getCString()); 88 errorCategoryNames[category], pos, sanitized->getCString());
77 } else { 89 } else {
78 fprintf(stderr, "%s: %s\n", 90 fprintf(stderr, "%s: %s\n",
79 errorCategoryNames[category], s->getCString()); 91 errorCategoryNames[category], sanitized->getCString());
80 } 92 }
81 fflush(stderr); 93 fflush(stderr);
82 } 94 }
83 delete s; 95 delete s;
96 delete sanitized;
84} 97}