Changeset 41909 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Mar 23, 2009, 8:13:57 AM (16 years ago)
Author:
[email protected]
Message:

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

Reviewed by Adam Roben.

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. We wrap this new code option in HAVE_LANGINFO_H,
since it is apparently not available in all platforms.

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

Legend:

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

    r41823 r41909  
    2828#include "DateInstance.h"
    2929#include <float.h>
     30
     31#if !PLATFORM(MAC) && HAVE(LANGINFO_H)
     32#include <langinfo.h>
     33#endif
     34
    3035#include <limits.h>
    3136#include <locale.h>
     
    182187static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, LocaleDateTimeFormat format)
    183188{
     189#if HAVE(LANGINFO_H)
     190    static const nl_item formats[] = { D_T_FMT, D_FMT, T_FMT };
     191#else
    184192    static const char* const formatStrings[] = { "%#c", "%#x", "%X" };
     193#endif
    185194 
    186195    // Offset year if needed
     
    191200        localTM.tm_year = equivalentYearForDST(year) - 1900;
    192201 
     202#if HAVE(LANGINFO_H)
     203    // We do not allow strftime to generate dates with 2-digits years,
     204    // both to avoid ambiguity, and a crash in strncpy, for years that
     205    // need offset.
     206    char* formatString = strdup(nl_langinfo(formats[format]));
     207    char* yPos = strchr(formatString, 'y');
     208    if (yPos)
     209        *yPos = 'Y';
     210#endif
     211
    193212    // Do the formatting
    194213    const int bufsize = 128;
    195214    char timebuffer[bufsize];
     215
     216#if HAVE(LANGINFO_H)
     217    size_t ret = strftime(timebuffer, bufsize, formatString, &localTM);
     218    free(formatString);
     219#else
    196220    size_t ret = strftime(timebuffer, bufsize, formatStrings[format], &localTM);
     221#endif
    197222 
    198223    if (ret == 0)
Note: See TracChangeset for help on using the changeset viewer.