Bug 19309 - uninitialised variable in PluginView
Summary: uninitialised variable in PluginView
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Plug-ins (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-29 09:09 PDT by Christian Persch (GNOME) (away; not reading bugmail)
Modified: 2008-06-08 11:17 PDT (History)
2 users (show)

See Also:


Attachments
patch (882 bytes, patch)
2008-05-29 09:10 PDT, Christian Persch (GNOME) (away; not reading bugmail)
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Persch (GNOME) (away; not reading bugmail) 2008-05-29 09:09:05 PDT
PluginView's NPP instance's pdata member is uninitialised. I was getting crashes in the totem plugins because of this; attached patch inits the var to 0. (This might have been a problem in the plugin itself, but I think it's better to be resilient against buggy plugins than just crash.)
Comment 1 Christian Persch (GNOME) (away; not reading bugmail) 2008-05-29 09:10:50 PDT
Created attachment 21410 [details]
patch
Comment 2 Darin Adler 2008-05-29 09:50:14 PDT
Comment on attachment 21410 [details]
patch

Isn't it the plug-in's responsibility to initialize pdata if it wants to use it?

I guess there's no harm in this in either case, so r=me.
Comment 3 Alp Toker 2008-05-29 10:01:23 PDT
The Moonlight plugin team also noticed they were relying on structures being zeroed when initialized, since this is Mozilla's behavour (at least on Linux/X11, I understand NPN_MemAlloc zeros as well as allocating while ours doesn't zero). They fixed the assumptions in their code, but I wonder if we should just go ahead and zero all newly-allocated data and structures passed to plugins as a rule rather than patching up issues individually as we discover them.

If plugins in the wild are assuming the allocated data is zeroed and transmitting uninitialised buffers over the network this could lead to security issues even in plugins that seem to work fine.
Comment 4 Alp Toker 2008-05-29 10:31:38 PDT
CC'ing Darin. We should probably skip this patch and match Mozilla's behaviour as I described since plugins are expecting zeroed input (even though the NPAPI docs warn plugin authors not to rely on this).
Comment 5 Darin Adler 2008-05-29 10:39:29 PDT
(In reply to comment #3)
> The Moonlight plugin team also noticed they were relying on structures being
> zeroed when initialized, since this is Mozilla's behavour (at least on
> Linux/X11, I understand NPN_MemAlloc zeros as well as allocating while ours
> doesn't zero). They fixed the assumptions in their code, but I wonder if we
> should just go ahead and zero all newly-allocated data and structures passed to
> plugins as a rule rather than patching up issues individually as we discover
> them.

The NPN_MemAlloc change sounds OK. Any other specific cases?
Comment 6 Alp Toker 2008-05-29 11:08:08 PDT
(In reply to comment #5)
> 
> The NPN_MemAlloc change sounds OK. Any other specific cases?
> 

The WebKit NPP, NPWindow, NPStream we pass to plugins are allocated as part of the C++ class, and the default memory allocator used for objects doesn't zero. There are some attempts to zero the fields, but if you take a look at PluginStream.cpp, the 'headers' field remains uninitialized until PluginStream::startStream(), by which time a plugin may already have tried to access it.

Perhaps it'd be more effective to allocate and initialize these structures explicitly rather than pointing the plugin to an offset in the C++ class?
Comment 7 Darin Adler 2008-05-29 12:07:33 PDT
(In reply to comment #6)
> Perhaps it'd be more effective to allocate and initialize these structures
> explicitly rather than pointing the plugin to an offset in the C++ class?

That sounds like overkill. It's trivial to initialize to 0:

    memset(&x, 0, sizeof(x));

So if we want initialization, then lets add it.
Comment 8 Darin Adler 2008-06-08 11:17:35 PDT
Committed revision 34443.