sal/CppunitTest_sal_osl.mk |    1 +
 sal/osl/unx/socket.cxx     |    5 ++++-
 sal/qa/osl/socket.cxx      |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

New commits:
commit 33bf4f0bcf941ee4609f558442035514f54cbc8a
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Mon May 31 09:36:28 2021 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Mon May 31 10:59:46 2021 +0200

    Replace inet_ntoa with inet_ntop
    
    ...as inet_ntoa is potentially not thread-safe; and add a test
    
    Change-Id: I9df945b006ba7194c3b1444c4886101c08339ad0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116425
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/sal/CppunitTest_sal_osl.mk b/sal/CppunitTest_sal_osl.mk
index b5e1b0658324..392da456459c 100644
--- a/sal/CppunitTest_sal_osl.mk
+++ b/sal/CppunitTest_sal_osl.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_osl,\
        sal/qa/osl/process/osl_Thread \
        sal/qa/osl/profile/osl_old_testprofile \
        sal/qa/osl/setthreadname/test-setthreadname \
+       sal/qa/osl/socket \
 ))
 
 $(eval $(call gb_CppunitTest_use_libraries,sal_osl,\
diff --git a/sal/osl/unx/socket.cxx b/sal/osl/unx/socket.cxx
index 376d6f1412ce..c78e43a9de93 100644
--- a/sal/osl/unx/socket.cxx
+++ b/sal/osl/unx/socket.cxx
@@ -1092,7 +1092,10 @@ oslSocketResult SAL_CALL 
osl_getDottedInetAddrOfSocketAddr(oslSocketAddr Addr, r
         return osl_Socket_Error;
     }
 
-    
rtl_uString_newFromAscii(ustrDottedInetAddr,inet_ntoa(pSystemInetAddr->sin_addr));
+    char buf[INET_ADDRSTRLEN];
+    auto const text = inet_ntop(AF_INET, &pSystemInetAddr->sin_addr, buf, 
INET_ADDRSTRLEN);
+    assert(text != nullptr);
+    rtl_uString_newFromAscii(ustrDottedInetAddr,text);
 
     return osl_Socket_Ok;
 
diff --git a/sal/qa/osl/socket.cxx b/sal/qa/osl/socket.cxx
new file mode 100644
index 000000000000..dab2621f2293
--- /dev/null
+++ b/sal/qa/osl/socket.cxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <osl/socket.h>
+#include <rtl/ustring.hxx>
+
+namespace
+{
+class SocketTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE(SocketTest);
+    CPPUNIT_TEST(test_getDottedInetAddrOfSocketAddr);
+    CPPUNIT_TEST_SUITE_END();
+
+    void test_getDottedInetAddrOfSocketAddr()
+    {
+        OUString const in("123.4.56.78");
+        auto const addr = osl_createInetSocketAddr(in.pData, 0);
+        CPPUNIT_ASSERT(addr != nullptr);
+        OUString out;
+        auto const res = osl_getDottedInetAddrOfSocketAddr(addr, &out.pData);
+        CPPUNIT_ASSERT_EQUAL(osl_Socket_Ok, res);
+        CPPUNIT_ASSERT_EQUAL(in, out);
+    }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SocketTest);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to