svl/source/numbers/zforfind.cxx | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
New commits: commit b44442b577b0ea15682b45fa68d9ac9e97e8be4e Author: Eike Rathke <er...@redhat.com> Date: Wed Jul 2 22:24:52 2014 +0200 resolved fdo#80166 check input against date acceptance pattern plausibility ... to prevent confusion of #.### input with D.M that then later is discarded as invalid date input instead of accepted as valid numeric input. (cherry picked from commit 836e504c859a5b67f7ab7ba842785951d41058cd) work around nonsense -Werror=maybe-uninitialized, fdo#80166 follow-up (cherry picked from commit 397362d8532d7b0abe38f2024dd2cefe2482d6a3) 0f9cf74550e43d174bf6ac75e70c51ab7f51ccf8 Change-Id: I178e28b7ef3b26d04eecc73e5e5c61ee41f89e32 Reviewed-on: https://gerrit.libreoffice.org/10037 Tested-by: David Tardon <dtar...@redhat.com> Reviewed-by: David Tardon <dtar...@redhat.com> diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx index 2302540..5aee40d 100644 --- a/svl/source/numbers/zforfind.cxx +++ b/svl/source/numbers/zforfind.cxx @@ -1186,6 +1186,8 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt ) } nDatePatternStart = nStartPatternAt; // remember start particle + const sal_Int32 nMonthsInYear = pFormatter->GetCalendar()->getNumberOfMonthsInYear(); + for (sal_Int32 nPattern=0; nPattern < sDateAcceptancePatterns.getLength(); ++nPattern) { sal_uInt16 nNext = nDatePatternStart; @@ -1195,12 +1197,46 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt ) sal_Int32 nPat = 0; for ( ; nPat < rPat.getLength() && bOk && nNext < nAnzStrings; ++nPat, ++nNext) { - switch (rPat[nPat]) + const sal_Unicode c = rPat[nPat]; + switch (c) { case 'Y': case 'M': case 'D': bOk = IsNum[nNext]; + if (bOk && (c == 'M' || c == 'D')) + { + // Check the D and M cases for plausibility. This also + // prevents recognition of date instead of number with a + // numeric group input if date separator is identical to + // group separator, for example with D.M as a pattern and + // #.### as a group. + sal_Int32 nMaxLen, nMaxVal; + switch (c) + { + case 'M': + nMaxLen = 2; + nMaxVal = nMonthsInYear; + break; + case 'D': + nMaxLen = 2; + nMaxVal = 31; + break; + default: + // This merely exists against + // -Werror=maybe-uninitialized, which is nonsense + // after the (c == 'M' || c == 'D') check above, + // but ... + nMaxLen = 2; + nMaxVal = 31; + } + bOk = (sStrArray[nNext].getLength() <= nMaxLen); + if (bOk) + { + sal_Int32 nNum = sStrArray[nNext].toInt32(); + bOk = (1 <= nNum && nNum <= nMaxVal); + } + } if (bOk) ++nDatePatternNumbers; break; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits