Changeset 20949 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Apr 19, 2007, 7:02:25 AM (18 years ago)
Author:
bdash
Message:

2007-04-19 Mark Rowe <[email protected]>

Reviewed by Darin.

Fix http://bugs.webkit.org/show_bug.cgi?id=13401
Bug 13401: Reproducible crash calling myArray.sort(compareFn) from within
a sort comparison function

  • kjs/array_object.cpp: (ArrayInstance::sort): Save/restore the static variables around calls to qsort to ensure nested calls to ArrayInstance::sort behave correctly.

2007-04-19 Mark Rowe <[email protected]>

Reviewed by Darin.

Test for http://bugs.webkit.org/show_bug.cgi?id=13401
Bug 13401: Reproducible crash calling myArray.sort(compareFn) from within
a sort comparison function

  • fast/js/array-sort-reentrance-expected.txt: Added.
  • fast/js/array-sort-reentrance.html: Added.
  • fast/js/resources/array-sort-reentrance.js: Added.
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r20867 r20949  
     12007-04-19  Mark Rowe  <[email protected]>
     2
     3        Reviewed by Darin.
     4
     5        Fix http://bugs.webkit.org/show_bug.cgi?id=13401
     6        Bug 13401: Reproducible crash calling myArray.sort(compareFn) from within
     7        a sort comparison function
     8
     9        * kjs/array_object.cpp:
     10        (ArrayInstance::sort): Save/restore the static variables around calls to qsort
     11        to ensure nested calls to ArrayInstance::sort behave correctly.
     12
    1132007-04-12  Deneb Meketa  <[email protected]>
    214
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r20569 r20949  
    285285}
    286286
    287 static ExecState *execForCompareByStringForQSort;
     287static ExecState* execForCompareByStringForQSort = 0;
    288288
    289289static int compareByStringForQSort(const void *a, const void *b)
     
    301301}
    302302
    303 void ArrayInstance::sort(ExecState *exec)
     303void ArrayInstance::sort(ExecState* exec)
    304304{
    305305    int lengthNotIncludingUndefined = pushUndefinedObjectsToEnd(exec);
    306    
     306
     307    ExecState* oldExec = execForCompareByStringForQSort;
    307308    execForCompareByStringForQSort = exec;
    308     qsort(storage, lengthNotIncludingUndefined, sizeof(JSValue *), compareByStringForQSort);
    309     execForCompareByStringForQSort = 0;
     309    qsort(storage, lengthNotIncludingUndefined, sizeof(JSValue*), compareByStringForQSort);
     310    execForCompareByStringForQSort = oldExec;
    310311}
    311312
     
    326327};
    327328
    328 static CompareWithCompareFunctionArguments *compareWithCompareFunctionArguments;
     329static CompareWithCompareFunctionArguments* compareWithCompareFunctionArguments = 0;
    329330
    330331static int compareWithCompareFunctionForQSort(const void *a, const void *b)
     
    349350}
    350351
    351 void ArrayInstance::sort(ExecState *exec, JSObject *compareFunction)
     352void ArrayInstance::sort(ExecState* exec, JSObject* compareFunction)
    352353{
    353354    int lengthNotIncludingUndefined = pushUndefinedObjectsToEnd(exec);
    354    
     355
     356    CompareWithCompareFunctionArguments* oldArgs = compareWithCompareFunctionArguments;
    355357    CompareWithCompareFunctionArguments args(exec, compareFunction);
    356358    compareWithCompareFunctionArguments = &args;
    357     qsort(storage, lengthNotIncludingUndefined, sizeof(JSValue *), compareWithCompareFunctionForQSort);
    358     compareWithCompareFunctionArguments = 0;
     359    qsort(storage, lengthNotIncludingUndefined, sizeof(JSValue*), compareWithCompareFunctionForQSort);
     360    compareWithCompareFunctionArguments = oldArgs;
    359361}
    360362
Note: See TracChangeset for help on using the changeset viewer.