Merge from vendor branch TNF:
[pkgsrcv2.git] / print / xpdf / patches / patch-aq
1 $NetBSD$
2
3 Fix arbitrary code execution with embedded fonts (CVE-2008-1693).
4
5 --- xpdf/Object.h.orig  2007-02-27 22:05:52.000000000 +0000
6 +++ xpdf/Object.h
7 @@ -68,17 +68,18 @@ enum ObjType {
8  //------------------------------------------------------------------------
9  
10  #ifdef DEBUG_MEM
11 -#define initObj(t) ++numAlloc[type = t]
12 +#define initObj(t) zeroUnion(); ++numAlloc[type = t]
13  #else
14 -#define initObj(t) type = t
15 +#define initObj(t) zeroUnion(); type = t
16  #endif
17  
18  class Object {
19  public:
20 -
21 +  // attempt to clear the anonymous union
22 +  void zeroUnion() { this->name = NULL; }
23    // Default constructor.
24    Object():
25 -    type(objNone) {}
26 +    type(objNone) { zeroUnion(); }
27  
28    // Initialize an object.
29    Object *initBool(GBool boolnA)
30 @@ -220,16 +221,16 @@ private:
31  #include "Array.h"
32  
33  inline int Object::arrayGetLength()
34 -  { return array->getLength(); }
35 +  { if (type != objArray) return 0; return array->getLength(); }
36  
37  inline void Object::arrayAdd(Object *elem)
38 -  { array->add(elem); }
39 +  { if (type == objArray) array->add(elem); }
40  
41  inline Object *Object::arrayGet(int i, Object *obj)
42 -  { return array->get(i, obj); }
43 +  { if (type != objArray) return obj->initNull(); return array->get(i, obj); }
44  
45  inline Object *Object::arrayGetNF(int i, Object *obj)
46 -  { return array->getNF(i, obj); }
47 +  { if (type != objArray) return obj->initNull(); return array->getNF(i, obj); }
48  
49  //------------------------------------------------------------------------
50  // Dict accessors.
51 @@ -238,31 +239,31 @@ inline Object *Object::arrayGetNF(int i,
52  #include "Dict.h"
53  
54  inline int Object::dictGetLength()
55 -  { return dict->getLength(); }
56 +  { if (type != objDict) return 0; return dict->getLength(); }
57  
58  inline void Object::dictAdd(char *key, Object *val)
59 -  { dict->add(key, val); }
60 +  { if (type == objDict) dict->add(key, val); }
61  
62  inline GBool Object::dictIs(char *dictType)
63 -  { return dict->is(dictType); }
64 +  { return (type == objDict) && dict->is(dictType); }
65  
66  inline GBool Object::isDict(char *dictType)
67    { return type == objDict && dictIs(dictType); }
68  
69  inline Object *Object::dictLookup(char *key, Object *obj)
70 -  { return dict->lookup(key, obj); }
71 +  { if (type != objDict) return obj->initNull(); return dict->lookup(key, obj); }
72  
73  inline Object *Object::dictLookupNF(char *key, Object *obj)
74 -  { return dict->lookupNF(key, obj); }
75 +  { if (type != objDict) return obj->initNull(); return dict->lookupNF(key, obj); }
76  
77  inline char *Object::dictGetKey(int i)
78 -  { return dict->getKey(i); }
79 +  { if (type != objDict) return NULL; return dict->getKey(i); }
80  
81  inline Object *Object::dictGetVal(int i, Object *obj)
82 -  { return dict->getVal(i, obj); }
83 +  { if (type != objDict) return obj->initNull(); return dict->getVal(i, obj); }
84  
85  inline Object *Object::dictGetValNF(int i, Object *obj)
86 -  { return dict->getValNF(i, obj); }
87 +  { if (type != objDict) return obj->initNull(); return dict->getValNF(i, obj); }
88  
89  //------------------------------------------------------------------------
90  // Stream accessors.
91 @@ -271,33 +272,33 @@ inline Object *Object::dictGetValNF(int 
92  #include "Stream.h"
93  
94  inline GBool Object::streamIs(char *dictType)
95 -  { return stream->getDict()->is(dictType); }
96 +  { return (type == objStream) && stream->getDict()->is(dictType); }
97  
98  inline GBool Object::isStream(char *dictType)
99 -  { return type == objStream && streamIs(dictType); }
100 +  { return (type == objStream) && streamIs(dictType); }
101  
102  inline void Object::streamReset()
103 -  { stream->reset(); }
104 +  { if (type == objStream) stream->reset(); }
105  
106  inline void Object::streamClose()
107 -  { stream->close(); }
108 +  { if (type == objStream) stream->close(); }
109  
110  inline int Object::streamGetChar()
111 -  { return stream->getChar(); }
112 +  { if (type != objStream) return EOF; return stream->getChar(); }
113  
114  inline int Object::streamLookChar()
115 -  { return stream->lookChar(); }
116 +  { if (type != objStream) return EOF; return stream->lookChar(); }
117  
118  inline char *Object::streamGetLine(char *buf, int size)
119 -  { return stream->getLine(buf, size); }
120 +  { if (type != objStream) return NULL; return stream->getLine(buf, size); }
121  
122  inline Guint Object::streamGetPos()
123 -  { return stream->getPos(); }
124 +  { if (type != objStream) return 0; return stream->getPos(); }
125  
126  inline void Object::streamSetPos(Guint pos, int dir)
127 -  { stream->setPos(pos, dir); }
128 +  { if (type == objStream) stream->setPos(pos, dir); }
129  
130  inline Dict *Object::streamGetDict()
131 -  { return stream->getDict(); }
132 +  { if (type != objStream) return NULL; return stream->getDict(); }
133  
134  #endif