[Libreoffice-commits] core.git: cui/source
Stephan Bergmann
sbergman at redhat.com
Mon Jan 29 10:00:41 UTC 2018
cui/source/options/optinet2.cxx | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
New commits:
commit 13c744e33f781cf1a261c776119f08b043efef79
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Jan 26 18:33:05 2018 +0100
Improve code checking for a valid port number
Change-Id: If827ffaee9a2aa861a0746353bdbfd5df1049303
Reviewed-on: https://gerrit.libreoffice.org/48716
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/cui/source/options/optinet2.cxx b/cui/source/options/optinet2.cxx
index 4a2064101141..40ae7acea0c0 100644
--- a/cui/source/options/optinet2.cxx
+++ b/cui/source/options/optinet2.cxx
@@ -19,6 +19,7 @@
#include <sal/config.h>
+#include <o3tl/string_view.hxx>
#include <officecfg/Office/Common.hxx>
#include <officecfg/Office/Security.hxx>
#include <tools/config.hxx>
@@ -98,7 +99,24 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::sfx2;
-// static ----------------------------------------------------------------
+namespace {
+
+bool isValidPort(OUString const & value) {
+ if (!comphelper::string::isdigitAsciiString(value)) {
+ return false;
+ }
+ auto const n = value.toUInt64();
+ if (n > 65535) {
+ return false;
+ }
+ if (n != 0) {
+ return true;
+ }
+ // Overflow in OUString::toUInt64 returns 0, so need to check value contains only zeroes:
+ return o3tl::u16string_view(value).find_first_not_of(u'0') == o3tl::u16string_view::npos;
+}
+
+}
VCL_BUILDER_FACTORY_ARGS(SvxNoSpaceEdit, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK)
@@ -128,10 +146,7 @@ void SvxNoSpaceEdit::Modify()
if ( bOnlyNumeric )
{
- OUString aValue = GetText();
-
- if ( !comphelper::string::isdigitAsciiString(aValue) || static_cast<long>(aValue.toInt32()) > USHRT_MAX )
- // the maximum value of a port number is USHRT_MAX
+ if ( !isValidPort(GetText()) )
ScopedVclPtrInstance<MessageDialog>(this, CuiResId( RID_SVXSTR_OPT_PROXYPORTS))->Execute();
}
}
@@ -527,9 +542,7 @@ IMPL_LINK( SvxProxyTabPage, ProxyHdl_Impl, ListBox&, rBox, void )
IMPL_STATIC_LINK( SvxProxyTabPage, LoseFocusHdl_Impl, Control&, rControl, void )
{
Edit* pEdit = static_cast<Edit*>(&rControl);
- OUString aValue = pEdit->GetText();
-
- if ( !comphelper::string::isdigitAsciiString(aValue) || static_cast<long>(aValue.toInt32()) > USHRT_MAX )
+ if ( !isValidPort(pEdit->GetText()) )
pEdit->SetText( OUString('0') );
}
More information about the Libreoffice-commits
mailing list