diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2023-05-01 21:14:14 +0200 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2023-05-03 13:55:30 +0200 |
commit | c4aa51f497db8b659cc66402dea7be88f57c2580 (patch) | |
tree | 90463eb609bee2a06492fe3230a3f0937aa82241 /unotools | |
parent | 2dadde7cf6999ba64c3db8ecf477e1c752af98f0 (diff) |
Related tdf#154769: XML Form add limits of length value for some datatype
length value for:
- year:4
- month and day:2
change ISO8601parseDate in unotools to return false when month or day length > 2
Change-Id: I807a8a784c8924750ae2c821de4be667e514e91f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151238
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/misc/datetime.cxx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/unotools/source/misc/datetime.cxx b/unotools/source/misc/datetime.cxx index 348dd0df4934..e2cc1f6d1150 100644 --- a/unotools/source/misc/datetime.cxx +++ b/unotools/source/misc/datetime.cxx @@ -350,14 +350,25 @@ bool ISO8601parseDate(std::u16string_view aDateStr, css::util::Date& rDate) sal_Int32 nDay = 30; sal_Int32 nIdx {0}; - if ( !convertNumber32( nYear, o3tl::getToken(aDateStr, 0, '-', nIdx ), 0, 9999 ) ) + auto strCurrentToken = o3tl::getToken(aDateStr, 0, '-', nIdx ); + if ( !convertNumber32( nYear, strCurrentToken, 0, 9999 ) ) return false; if ( nDateTokens >= 2 ) - if ( !convertNumber32( nMonth, o3tl::getToken(aDateStr, 0, '-', nIdx ), 0, 12 ) ) + { + strCurrentToken = o3tl::getToken(aDateStr, 0, '-', nIdx ); + if (strCurrentToken.size() > 2) + return false; + if ( !convertNumber32( nMonth, strCurrentToken, 0, 12 ) ) return false; + } if ( nDateTokens >= 3 ) - if ( !convertNumber32( nDay, o3tl::getToken(aDateStr, 0, '-', nIdx ), 0, 31 ) ) + { + strCurrentToken = o3tl::getToken(aDateStr, 0, '-', nIdx ); + if (strCurrentToken.size() > 2) + return false; + if ( !convertNumber32( nDay, strCurrentToken, 0, 31 ) ) return false; + } rDate.Year = static_cast<sal_uInt16>(nYear); rDate.Month = static_cast<sal_uInt16>(nMonth); |