Changeset 41818 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Mar 18, 2009, 4:21:51 PM (16 years ago)
Author:
[email protected]
Message:

2009-03-18 Gustavo Noronha Silva <Gustavo Noronha Silva> and Thadeu Lima de Souza Cascardo <[email protected]>

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=24674
Crashes in !PLATFORM(MAC)'s formatLocaleDate, in very specific situations

Make sure strftime never returns 2-digits years to avoid ambiguity and
a crash.

  • runtime/DatePrototype.cpp: (JSC::formatLocaleDate):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/DatePrototype.cpp

    r40046 r41818  
    2828#include "DateInstance.h"
    2929#include <float.h>
     30#include <langinfo.h>
    3031#include <limits.h>
    3132#include <locale.h>
     
    182183static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, LocaleDateTimeFormat format)
    183184{
    184     static const char* const formatStrings[] = { "%#c", "%#x", "%X" };
     185    static const nl_item formats[] = { D_T_FMT, D_FMT, T_FMT };
    185186 
    186187    // Offset year if needed
     
    191192        localTM.tm_year = equivalentYearForDST(year) - 1900;
    192193 
     194    // We do not allow strftime to generate dates with 2-digits years,
     195    // both to avoid ambiguity, and a crash in strncpy, for years that
     196    // need offset.
     197    char* formatString = strdup(nl_langinfo(formats[format]));
     198    char* yPos = strchr(formatString, 'y');
     199    if (yPos)
     200        *yPos = 'Y';
     201
    193202    // Do the formatting
    194203    const int bufsize = 128;
    195204    char timebuffer[bufsize];
    196     size_t ret = strftime(timebuffer, bufsize, formatStrings[format], &localTM);
     205    size_t ret = strftime(timebuffer, bufsize, formatString, &localTM);
     206
     207    free(formatString);
    197208 
    198209    if (ret == 0)
Note: See TracChangeset for help on using the changeset viewer.