VirtualBox

Changeset 5969 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Dec 5, 2007 6:34:07 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
26546
Message:

Main: Fixed a bug in CFGLDRQueryDateTime() that could trap VBoxSVC if the lastStateChange VM attribute were close to the Epoch (precisely, if lastStateChange + timezone_offset went before midnight, 1970).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/cfgldr.cpp

    r5523 r5969  
    6060#include <iprt/alloc.h>
    6161
    62 /// @todo (dmik) until RTTimeImplode and friends are done
     62/// @todo (dmik) until RTTimeNormalize and friends are done
    6363#include <time.h>
    6464
     
    27992799    }
    28002800
    2801     // query as UTF8 string
     2801    /* query as UTF8 string */
    28022802    unsigned size = 0;
    28032803    int rc = CFGLDRQueryString(hnode, pszName, NULL, 0, &size);
     
    28102810    if (VBOX_SUCCESS(rc)) do
    28112811    {
    2812         // Parse xsd:dateTime. The format is:
    2813         // '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
    2814         // where zzzzzz is: (('+' | '-') hh ':' mm) | 'Z'
     2812        /* Parse xsd:dateTime. The format is:
     2813         * '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
     2814         * where zzzzzz is: (('+' | '-') hh ':' mm) | 'Z' */
    28152815        uint32_t yyyy = 0;
    28162816        uint16_t mm = 0, dd = 0, hh = 0, mi = 0, ss = 0;
     
    28222822        }
    28232823
    2824         // currently, we accept only the UTC timezone ('Z'),
    2825         // ignoring fractional seconds, if present
     2824        /* currently, we accept only the UTC timezone ('Z'),
     2825         * ignoring fractional seconds, if present */
    28262826        if (pszBuf[0] == 'Z' ||
    28272827            (pszBuf[0] == '.' && pszBuf[strlen(pszBuf)-1] == 'Z'))
    28282828        {
    2829             // start with an error
     2829            /* start with an error */
    28302830            rc = VERR_PARSE_ERROR;
    28312831
    28322832#if 0
    2833             RTTIME time = { yyyy, mm, 0, 0, dd, hh, mm, ss, 0,
     2833            RTTIME time = { yyyy, (uint8_t) mm, 0, 0, (uint8_t) dd,
     2834                            (uint8_t) hh, (uint8_t) mm, (uint8_t) ss, 0,
    28342835                            RTTIME_FLAGS_TYPE_UTC };
    2835             if (RTTimeNormalize(&time))
     2836            if (RTTimeNormalize (&time))
    28362837            {
    28372838                RTTIMESPEC timeSpec;
    2838                 if (RTTimeImplode(&time, &timeSpec))
     2839                if (RTTimeImplode (&timeSpec, &time))
    28392840                {
    2840                     *pi64Value = RTTimeSpecGetMilli(&timeSpec);
     2841                    *pi64Value = RTTimeSpecGetMilli (&timeSpec);
    28412842                    rc = VINF_SUCCESS;
    28422843                }
    28432844            }
    28442845#else
    2845             /// @todo (dmik) until RTTimeImplode and friends are done
     2846            /// @todo (dmik) until RTTimeNormalize and friends are done
    28462847            int isdst = 0;
    28472848            {
     
    28602861            time.tm_year = yyyy - 1900;   /* Year less 1900 */
    28612862            time_t t = mktime(&time);
    2862             // mktime expects local time, but we supply it UTC,
    2863             // do a trick to get the right time value
     2863            /* mktime expects local time, but we supply it UTC, do a dirty
     2864             * trick to get the right time value. Note that the trick doesn't
     2865             * work when UTC + timezone_offset goes before midnight, 1.1.1970
     2866             * (gmtime() will return NULL on failure) */
    28642867            tm *dummytm = gmtime(&t);
    2865             dummytm->tm_isdst = isdst;
    2866             time_t delta = t - mktime(dummytm);
    2867             *pi64Value = t + delta;
    2868             *pi64Value *= 1000;
    2869             rc = VINF_SUCCESS;
     2868            if (dummytm)
     2869            {
     2870                dummytm->tm_isdst = isdst;
     2871                time_t delta = t - mktime(dummytm);
     2872                *pi64Value = t + delta;
     2873                *pi64Value *= 1000;
     2874                rc = VINF_SUCCESS;
     2875            }
    28702876#endif
    28712877        }
     
    28942900    RTTimeExplode(&time, &timeSpec);
    28952901#else
    2896     /// @todo (dmik) until RTTimeImplode and friends are done
     2902    /// @todo (dmik) until RTTimeNormalize and friends are done
    28972903    time_t t = (time_t)(i64Value / 1000);
    28982904    tm *ptm = gmtime(&t);
     
    29142920                (uint16_t) time.u8Hour, (uint16_t) time.u8Minute, (uint16_t) time.u8Second);
    29152921#else
    2916                 /// @todo (dmik) until RTTimeImplode and friends are done
     2922                /// @todo (dmik) until RTTimeNormalize and friends are done
    29172923                time.tm_year, time.tm_mon, time.tm_mday,
    29182924                time.tm_hour, time.tm_min, time.tm_sec);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette