~jconti/ubuntu/oneiric/webkit/fix_doc_path

« back to all changes in this revision

Viewing changes to WebCore/page/JavaScriptProfileNode.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2008-09-27 08:57:48 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080927085748-yhzld00w0rekp961
Tags: 1.0.1-4
WebCore/dom/Document.*, WebCore/loader/DocLoader.*: Avoid DoS via
crafted CSS import statements. Fixes: CVE-2008-3632. Closes: #499771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 * 1. Redistributions of source code must retain the above copyright
 
8
 *    notice, this list of conditions and the following disclaimer.
 
9
 * 2. Redistributions in binary form must reproduce the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer in the
 
11
 *    documentation and/or other materials provided with the distribution.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
#include "JavaScriptProfileNode.h"
 
28
 
 
29
#include "JSDOMBinding.h"
 
30
#include <profiler/ProfileNode.h>
 
31
#include <JavaScriptCore/APICast.h>
 
32
#include <JavaScriptCore/JSObjectRef.h>
 
33
#include <JavaScriptCore/JSContextRef.h>
 
34
#include <JavaScriptCore/JSRetainPtr.h>
 
35
#include <JavaScriptCore/JSStringRef.h>
 
36
#include <kjs/value.h>
 
37
 
 
38
using namespace KJS;
 
39
 
 
40
namespace WebCore {
 
41
 
 
42
// Cache
 
43
 
 
44
typedef HashMap<ProfileNode*, JSValue*> ProfileNodeMap;
 
45
 
 
46
static ProfileNodeMap& ProfileNodeCache()
 
47
 
48
    static ProfileNodeMap staticProfileNodes;
 
49
    return staticProfileNodes;
 
50
}
 
51
 
 
52
static JSValueRef getFunctionName(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
53
{
 
54
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
55
        return JSValueMakeUndefined(ctx);
 
56
 
 
57
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
58
    JSRetainPtr<JSStringRef> functionNameString(Adopt, JSStringCreateWithCharacters(profileNode->functionName().data(), profileNode->functionName().size()));
 
59
    return JSValueMakeString(ctx, functionNameString.get());
 
60
}
 
61
 
 
62
static JSValueRef getURL(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
63
{
 
64
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
65
        return JSValueMakeUndefined(ctx);
 
66
 
 
67
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
68
    JSRetainPtr<JSStringRef> urlString(Adopt, JSStringCreateWithCharacters(profileNode->url().data(), profileNode->url().size()));
 
69
    return JSValueMakeString(ctx, urlString.get());
 
70
}
 
71
 
 
72
static JSValueRef getLineNumber(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
73
{
 
74
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
75
        return JSValueMakeUndefined(ctx);
 
76
 
 
77
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
78
    return JSValueMakeNumber(ctx, profileNode->lineNumber());
 
79
}
 
80
 
 
81
static JSValueRef getTotalTime(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
82
{
 
83
    KJS::JSLock lock;
 
84
 
 
85
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
86
        return JSValueMakeUndefined(ctx);
 
87
 
 
88
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
89
    return JSValueMakeNumber(ctx, profileNode->totalTime());
 
90
}
 
91
 
 
92
static JSValueRef getSelfTime(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
93
{
 
94
    KJS::JSLock lock;
 
95
 
 
96
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
97
        return JSValueMakeUndefined(ctx);
 
98
 
 
99
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
100
    return JSValueMakeNumber(ctx, profileNode->selfTime());
 
101
}
 
102
 
 
103
static JSValueRef getTotalPercent(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
104
{
 
105
    KJS::JSLock lock;
 
106
 
 
107
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
108
        return JSValueMakeUndefined(ctx);
 
109
 
 
110
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
111
    return JSValueMakeNumber(ctx, profileNode->totalPercent());
 
112
}
 
113
 
 
114
static JSValueRef getSelfPercent(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
115
{
 
116
    KJS::JSLock lock;
 
117
 
 
118
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
119
        return JSValueMakeUndefined(ctx);
 
120
 
 
121
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
122
    return JSValueMakeNumber(ctx, profileNode->selfPercent());
 
123
}
 
124
 
 
125
static JSValueRef getNumberOfCalls(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
126
{
 
127
    KJS::JSLock lock;
 
128
 
 
129
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
130
        return JSValueMakeUndefined(ctx);
 
131
 
 
132
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
133
    return JSValueMakeNumber(ctx, profileNode->numberOfCalls());
 
134
}
 
135
 
 
136
static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
137
{
 
138
    KJS::JSLock lock;
 
139
 
 
140
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
141
        return JSValueMakeUndefined(ctx);
 
142
 
 
143
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
144
    const Vector<RefPtr<ProfileNode> >& children = profileNode->children();
 
145
 
 
146
    JSObjectRef global = JSContextGetGlobalObject(ctx);
 
147
 
 
148
    JSRetainPtr<JSStringRef> arrayString(Adopt, JSStringCreateWithUTF8CString("Array"));
 
149
 
 
150
    JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, arrayString.get(), exception);
 
151
    if (exception && *exception)
 
152
        return JSValueMakeUndefined(ctx);
 
153
 
 
154
    JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception);
 
155
    if (exception && *exception)
 
156
        return JSValueMakeUndefined(ctx);
 
157
 
 
158
    JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception);
 
159
    if (exception && *exception)
 
160
        return JSValueMakeUndefined(ctx);
 
161
 
 
162
    JSRetainPtr<JSStringRef> pushString(Adopt, JSStringCreateWithUTF8CString("push"));
 
163
    
 
164
    JSValueRef pushProperty = JSObjectGetProperty(ctx, result, pushString.get(), exception);
 
165
    if (exception && *exception)
 
166
        return JSValueMakeUndefined(ctx);
 
167
 
 
168
    JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception);
 
169
    if (exception && *exception)
 
170
        return JSValueMakeUndefined(ctx);
 
171
 
 
172
    for (Vector<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) {
 
173
        JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() ));
 
174
        JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception);
 
175
        if (exception && *exception)
 
176
            return JSValueMakeUndefined(ctx);
 
177
    }
 
178
 
 
179
    return result;
 
180
}
 
181
 
 
182
static JSValueRef getVisible(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
 
183
{
 
184
    KJS::JSLock lock;
 
185
 
 
186
    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
 
187
        return JSValueMakeUndefined(ctx);
 
188
 
 
189
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
 
190
    return JSValueMakeBoolean(ctx, profileNode->visible());
 
191
}
 
192
 
 
193
static void finalize(JSObjectRef object)
 
194
{
 
195
    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(object));
 
196
    ProfileNodeCache().remove(profileNode);
 
197
    profileNode->deref();
 
198
}
 
199
 
 
200
JSClassRef ProfileNodeClass()
 
201
{
 
202
    static JSStaticValue staticValues[] = {
 
203
        { "functionName", getFunctionName, 0, kJSPropertyAttributeNone },
 
204
        { "url", getURL, 0, kJSPropertyAttributeNone },
 
205
        { "lineNumber", getLineNumber, 0, kJSPropertyAttributeNone },
 
206
        { "totalTime", getTotalTime, 0, kJSPropertyAttributeNone },
 
207
        { "selfTime", getSelfTime, 0, kJSPropertyAttributeNone },
 
208
        { "totalPercent", getTotalPercent, 0, kJSPropertyAttributeNone },
 
209
        { "selfPercent", getSelfPercent, 0, kJSPropertyAttributeNone },
 
210
        { "numberOfCalls", getNumberOfCalls, 0, kJSPropertyAttributeNone },
 
211
        { "children", getChildren, 0, kJSPropertyAttributeNone },
 
212
        { "visible", getVisible, 0, kJSPropertyAttributeNone },
 
213
        { 0, 0, 0, 0 }
 
214
    };
 
215
 
 
216
    static JSClassDefinition classDefinition = {
 
217
        0, kJSClassAttributeNone, "ProfileNode", 0, staticValues, 0,
 
218
        0, finalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
 
219
    };
 
220
 
 
221
    static JSClassRef ProfileNodeClass = JSClassCreate(&classDefinition);
 
222
    return ProfileNodeClass;
 
223
}
 
224
 
 
225
JSValue* toJS(ExecState* exec, ProfileNode* ProfileNode)
 
226
{
 
227
    if (!ProfileNode)
 
228
        return jsNull();
 
229
 
 
230
    JSValue* ProfileNodeWrapper = ProfileNodeCache().get(ProfileNode);
 
231
    if (ProfileNodeWrapper)
 
232
        return ProfileNodeWrapper;
 
233
 
 
234
    ProfileNode->ref();
 
235
 
 
236
    ProfileNodeWrapper = toJS(JSObjectMake(toRef(exec), ProfileNodeClass(), static_cast<void*>(ProfileNode)));
 
237
    ProfileNodeCache().set(ProfileNode, ProfileNodeWrapper);
 
238
    return ProfileNodeWrapper;
 
239
}
 
240
 
 
241
 
 
242
} // namespace WebCore