Bug 30502 - Dereference of uninitialized variable
Summary: Dereference of uninitialized variable
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P3 Minor
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-18 22:48 PDT by Kent Tamura
Modified: 2009-10-19 10:36 PDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (1.36 KB, patch)
2009-10-18 23:11 PDT, Kent Tamura
ap: review-
Details | Formatted Diff | Diff
Proposed patch (rev.2) (1.31 KB, patch)
2009-10-19 00:30 PDT, Kent Tamura
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Tamura 2009-10-18 22:48:34 PDT
WebCore/dom/Element.cpp setBooleanAttribute();

        ExceptionCode ex;
        removeAttribute(name, ex);

removeAttribute():
  void Element::removeAttribute(const QualifiedName& name, ExceptionCode& ec)
  {
      if (namedAttrMap) {
          namedAttrMap->removeNamedItem(name, ec);
          if (ec == NOT_FOUND_ERR)
              ec = 0;
      }
  }

removeNamedItem() doesn't set any value to ec if the specified attribute exists.  So, if removeAttribute() is called by setBooleanAttribute(), uninitialized ec can be referred at "if (ec == NOT_FOUND_ERR)".

Note: This never makes a real bug because ex in setBooleanAttribute() is not used after removeAttribute() call.
Valgrind complaints about this.
Comment 1 Kent Tamura 2009-10-18 23:11:45 PDT
Created attachment 41398 [details]
Proposed patch
Comment 2 Mark Rowe (bdash) 2009-10-18 23:52:14 PDT
Wouldn’t it make more sense to initialize the variable at the level that it matters?  setBooleanAttribute doesn’t care about the exception code so there’s no need for it to do anything with it.  After your change the code in removeAttribute will still do the wrong thing if called by another caller.
Comment 3 Kent Tamura 2009-10-18 23:55:30 PDT
(In reply to comment #2)
> Wouldn’t it make more sense to initialize the variable at the level that it
> matters?  setBooleanAttribute doesn’t care about the exception code so there’s
> no need for it to do anything with it.  After your change the code in
> removeAttribute will still do the wrong thing if called by another caller.

I think our convention for ExceptionCode is "initialize it with 0 when it is declared."
Comment 4 Kent Tamura 2009-10-19 00:00:56 PDT
> I think our convention for ExceptionCode is "initialize it with 0 when it is
> declared."

So, if removeAttribute() set 0 before removenamedItem() and other callers initialize ec with 0, we would have redundant initialization.
Comment 5 Mark Rowe (bdash) 2009-10-19 00:14:54 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > Wouldn’t it make more sense to initialize the variable at the level that it
> > matters?  setBooleanAttribute doesn’t care about the exception code so there’s
> > no need for it to do anything with it.  After your change the code in
> > removeAttribute will still do the wrong thing if called by another caller.
> 
> I think our convention for ExceptionCode is "initialize it with 0 when it is
> declared.”

A quick grep in WebCore for “ExceptionCode ec;” shows that is not the case.
Comment 6 Alexey Proskuryakov 2009-10-19 00:20:04 PDT
Comment on attachment 41398 [details]
Proposed patch

As Mark said - if a caller doesn't plan to look at ExceptionCode, it can pass an uninitialized value. See bug 21939 for more detailed discussion of the current policy (especially comments 3 and 12 there).
Comment 7 Kent Tamura 2009-10-19 00:30:01 PDT
Created attachment 41400 [details]
Proposed patch (rev.2)

ok, I follow it.

Updated the patch so that removeAttribute() initializes ec.
Comment 8 Alexey Proskuryakov 2009-10-19 08:14:34 PDT
Comment on attachment 41400 [details]
Proposed patch (rev.2)

r=me

It may make sense to add a comment explaining that this assignment is only needed to please tools like valgrind - since it's useless otherwise, people will be tempted to remove it.
Comment 9 Yong Li 2009-10-19 08:49:35 PDT
Comment on attachment 41400 [details]
Proposed patch (rev.2)

Let commit bot land it
Comment 10 WebKit Commit Bot 2009-10-19 09:42:44 PDT
Comment on attachment 41400 [details]
Proposed patch (rev.2)

Rejecting patch 41400 from commit-queue.

Failed to run "['WebKitTools/Scripts/run-webkit-tests', '--no-launch-safari', '--quiet', '--exit-after-n-failures=1']" exit_code: 1
Running build-dumprendertree
Running tests from /Users/eseidel/Projects/CommitQueue/LayoutTests
Testing 11468 test cases.
http/tests/navigation/postredirect-reload.html -> crashed

Exiting early after 1 failures. 8689 tests run.
390.95s total testing time

8688 test cases (99%) succeeded
1 test case (<1%) crashed
5 test cases (<1%) had stderr output
Comment 11 Eric Seidel (no email) 2009-10-19 10:11:57 PDT
Comment on attachment 41400 [details]
Proposed patch (rev.2)

That crash looks unrelated to your patch.  I've filed bug 30519.  Adding this back to the commit-queue.
Comment 12 WebKit Commit Bot 2009-10-19 10:36:06 PDT
Comment on attachment 41400 [details]
Proposed patch (rev.2)

Clearing flags on attachment: 41400

Committed r49792: <http://trac.webkit.org/changeset/49792>
Comment 13 WebKit Commit Bot 2009-10-19 10:36:11 PDT
All reviewed patches have been landed.  Closing bug.