You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2020/07/10 19:48:11 UTC
[qpid-proton] branch master updated: PROTON-2077 Remove
pni_snprintf; not needed with Visual Studio 2015 and up
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/master by this push:
new 7075502 PROTON-2077 Remove pni_snprintf; not needed with Visual Studio 2015 and up
7075502 is described below
commit 7075502a688c5cb2047803d118e8a7d94630e880
Author: Jiri Danek <jd...@redhat.com>
AuthorDate: Tue May 5 18:14:11 2020 +0200
PROTON-2077 Remove pni_snprintf; not needed with Visual Studio 2015 and up
This fixes overflow issue found earlier by Coverity in pni_snprintf.
---
c/CMakeLists.txt | 2 +-
c/src/compiler/msvc/snprintf.c | 56 ------------------------------------------
c/src/core/engine.c | 2 +-
c/src/core/error.c | 3 ++-
c/src/core/object/string.c | 2 +-
c/src/core/transport.c | 4 +--
c/src/messenger/messenger.c | 4 +--
c/src/platform/platform.c | 2 +-
c/src/platform/platform.h | 10 +-------
c/src/reactor/io/posix/io.c | 2 +-
c/src/reactor/io/windows/io.c | 2 +-
c/src/ssl/openssl.c | 7 +++---
c/src/ssl/schannel.cpp | 9 ++++---
c/tests/fuzz/CMakeLists.txt | 6 +----
python/setup.py.in | 1 -
15 files changed, 23 insertions(+), 89 deletions(-)
diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt
index cd2d665..f0f7f83 100644
--- a/c/CMakeLists.txt
+++ b/c/CMakeLists.txt
@@ -197,7 +197,7 @@ set(C_EXAMPLE_LINK_FLAGS "${SANITIZE_FLAGS}")
set(qpid-proton-platform_GNU src/compiler/gcc/start.c)
set(qpid-proton-platform_Clang src/compiler/gcc/start.c)
-set(qpid-proton-platform_MSVC src/compiler/msvc/snprintf.c src/compiler/msvc/start.c)
+set(qpid-proton-platform_MSVC src/compiler/msvc/start.c)
set(qpid-proton-platform ${qpid-proton-platform_${CMAKE_C_COMPILER_ID}})
diff --git a/c/src/compiler/msvc/snprintf.c b/c/src/compiler/msvc/snprintf.c
deleted file mode 100644
index 49a853c..0000000
--- a/c/src/compiler/msvc/snprintf.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include "platform/platform.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-
-// [v]snprintf on Windows only matches C99 when no errors or overflow.
-// Note: [v]snprintf behavior changed in VS2015 to be C99 compliant.
-// vsnprintf_s is unchanged. This platform code can go away some day.
-
-
-int pni_vsnprintf(char *buf, size_t count, const char *fmt, va_list ap) {
- if (fmt == NULL)
- return -1;
- if ((buf == NULL) && (count > 0))
- return -1;
- if (count > 0) {
- int n = vsnprintf_s(buf, count, _TRUNCATE, fmt, ap);
- if (n >= 0) // no overflow
- return n; // same as C99
- buf[count-1] = '\0';
- }
- // separate call to get needed buffer size on overflow
- int n = _vscprintf(fmt, ap);
- if (n >= (int) count)
- return n;
- return -1;
-}
-
-int pni_snprintf(char *buf, size_t count, const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- int n = pni_vsnprintf(buf, count, fmt, ap);
- va_end(ap);
- return n;
-}
diff --git a/c/src/core/engine.c b/c/src/core/engine.c
index 0e313b9..19dcc63 100644
--- a/c/src/core/engine.c
+++ b/c/src/core/engine.c
@@ -2171,7 +2171,7 @@ int pn_condition_vformat(pn_condition_t *condition, const char *name, const char
return err;
char text[1024];
- size_t n = pni_vsnprintf(text, 1024, fmt, ap);
+ size_t n = vsnprintf(text, 1024, fmt, ap);
if (n >= sizeof(text))
text[sizeof(text)-1] = '\0';
err = pn_condition_set_description(condition, text);
diff --git a/c/src/core/error.c b/c/src/core/error.c
index d533a21..9ebe90d 100644
--- a/c/src/core/error.c
+++ b/c/src/core/error.c
@@ -31,6 +31,7 @@
#include <proton/session.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <assert.h>
@@ -83,7 +84,7 @@ int pn_error_vformat(pn_error_t *error, int code, const char *fmt, va_list ap)
{
assert(error);
char text[1024];
- int n = pni_vsnprintf(text, 1024, fmt, ap);
+ int n = vsnprintf(text, 1024, fmt, ap);
if (n >= 1024) {
text[1023] = '\0';
}
diff --git a/c/src/core/object/string.c b/c/src/core/object/string.c
index 6d429ec..b505306 100644
--- a/c/src/core/object/string.c
+++ b/c/src/core/object/string.c
@@ -230,7 +230,7 @@ int pn_string_vaddf(pn_string_t *string, const char *format, va_list ap)
while (true) {
va_copy(copy, ap);
- int err = pni_vsnprintf(string->bytes + string->size, string->capacity - string->size, format, copy);
+ int err = vsnprintf(string->bytes + string->size, string->capacity - string->size, format, copy);
va_end(copy);
if (err < 0) {
return err;
diff --git a/c/src/core/transport.c b/c/src/core/transport.c
index 7b81dda..dde697d 100644
--- a/c/src/core/transport.c
+++ b/c/src/core/transport.c
@@ -1114,7 +1114,7 @@ int pn_do_error(pn_transport_t *transport, const char *condition, const char *fm
char buf[1024];
if (fmt) {
// XXX: result
- pni_vsnprintf(buf, 1024, fmt, ap);
+ vsnprintf(buf, 1024, fmt, ap);
} else {
buf[0] = '\0';
}
@@ -1129,7 +1129,7 @@ int pn_do_error(pn_transport_t *transport, const char *condition, const char *fm
const char *first = pn_condition_get_description(cond);
if (first && fmt) {
char extended[2048];
- pni_snprintf(extended, 2048, "%s (%s)", first, buf);
+ snprintf(extended, 2048, "%s (%s)", first, buf);
pn_condition_set_description(cond, extended);
} else if (fmt) {
pn_condition_set_description(cond, buf);
diff --git a/c/src/messenger/messenger.c b/c/src/messenger/messenger.c
index bc7b57f..bb7999d 100644
--- a/c/src/messenger/messenger.c
+++ b/c/src/messenger/messenger.c
@@ -39,7 +39,7 @@
#include "core/log_private.h"
#include "core/util.h"
-#include "platform/platform.h" // pn_i_getpid, pn_i_now, pni_snprintf
+#include "platform/platform.h" // pn_i_getpid, pn_i_now
#include "platform/platform_fmt.h"
#include "store.h"
#include "subscription.h"
@@ -983,7 +983,7 @@ static void pn_condition_report(const char *pfx, pn_condition_t *condition)
pn_condition_redirect_port(condition));
} else if (pn_condition_is_set(condition)) {
char error[1024];
- pni_snprintf(error, 1024, "(%s) %s",
+ snprintf(error, 1024, "(%s) %s",
pn_condition_get_name(condition),
pn_condition_get_description(condition));
pn_error_report(pfx, error);
diff --git a/c/src/platform/platform.c b/c/src/platform/platform.c
index 393f75c..5cdb0a7 100644
--- a/c/src/platform/platform.c
+++ b/c/src/platform/platform.c
@@ -87,7 +87,7 @@ pn_timestamp_t pn_i_now(void)
static void pn_i_strerror(int errnum, char *buf, size_t buflen)
{
// PROTON-1029 provide a simple default in case strerror fails
- pni_snprintf(buf, buflen, "errno: %d", errnum);
+ snprintf(buf, buflen, "errno: %d", errnum);
#ifdef USE_STRERROR_R
strerror_r(errnum, buf, buflen);
#elif USE_STRERROR_S
diff --git a/c/src/platform/platform.h b/c/src/platform/platform.h
index 1b83429..30d29a6 100644
--- a/c/src/platform/platform.h
+++ b/c/src/platform/platform.h
@@ -69,15 +69,7 @@ int pn_i_error_from_errno(pn_error_t *error, const char *msg);
*/
int64_t pn_i_atoll(const char* num);
-int pni_snprintf(char *buf, size_t count, const char *fmt, ...);
-int pni_vsnprintf(char *buf, size_t count, const char *fmt, va_list ap);
-
-#ifndef _MSC_VER
-
-#define pni_snprintf snprintf
-#define pni_vsnprintf vsnprintf
-
-#else
+#ifdef _MSC_VER
#if !defined(S_ISDIR)
# define S_ISDIR(X) ((X) & _S_IFDIR)
diff --git a/c/src/reactor/io/posix/io.c b/c/src/reactor/io/posix/io.c
index 5a0de3b..2ddb5c0 100644
--- a/c/src/reactor/io/posix/io.c
+++ b/c/src/reactor/io/posix/io.c
@@ -218,7 +218,7 @@ pn_socket_t pn_accept(pn_io_t *io, pn_socket_t socket, char *name, size_t size)
return PN_INVALID_SOCKET;
} else {
pn_configure_sock(io, sock);
- pni_snprintf(name, size, "%s:%s", io->host, io->serv);
+ snprintf(name, size, "%s:%s", io->host, io->serv);
return sock;
}
}
diff --git a/c/src/reactor/io/windows/io.c b/c/src/reactor/io/windows/io.c
index 07692d1..d7d6f29 100644
--- a/c/src/reactor/io/windows/io.c
+++ b/c/src/reactor/io/windows/io.c
@@ -306,7 +306,7 @@ pn_socket_t pn_accept(pn_io_t *io, pn_socket_t listen_sock, char *name, size_t s
return INVALID_SOCKET;
} else {
pn_configure_sock(io, accept_sock);
- pni_snprintf(name, size, "%s:%s", io->host, io->serv);
+ snprintf(name, size, "%s:%s", io->host, io->serv);
if (listend) {
pni_iocpdesc_start(pni_iocpdesc_map_get(io->iocp, accept_sock));
}
diff --git a/c/src/ssl/openssl.c b/c/src/ssl/openssl.c
index 0ee5411..3a98200 100644
--- a/c/src/ssl/openssl.c
+++ b/c/src/ssl/openssl.c
@@ -52,6 +52,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
+#include <stdio.h>
/** @file
* SSL/TLS support API.
@@ -903,7 +904,7 @@ bool pn_ssl_get_cipher_name(pn_ssl_t *ssl0, char *buffer, size_t size )
if (ssl->ssl && (c = SSL_get_current_cipher( ssl->ssl ))) {
const char *v = SSL_CIPHER_get_name(c);
if (buffer && v) {
- pni_snprintf( buffer, size, "%s", v );
+ snprintf( buffer, size, "%s", v );
return true;
}
}
@@ -919,7 +920,7 @@ bool pn_ssl_get_protocol_name(pn_ssl_t *ssl0, char *buffer, size_t size )
if (ssl->ssl && (c = SSL_get_current_cipher( ssl->ssl ))) {
const char *v = SSL_CIPHER_get_version(c);
if (buffer && v) {
- pni_snprintf( buffer, size, "%s", v );
+ snprintf( buffer, size, "%s", v );
return true;
}
}
@@ -1486,7 +1487,7 @@ int pn_ssl_get_cert_fingerprint(pn_ssl_t *ssl0, char *fingerprint, size_t finger
char *cursor = fingerprint;
for (size_t i=0; i<len ; i++) {
- cursor += pni_snprintf((char *)cursor, fingerprint_length, "%02x", bytes[i]);
+ cursor += snprintf((char *)cursor, fingerprint_length, "%02x", bytes[i]);
fingerprint_length = fingerprint_length - 2;
}
diff --git a/c/src/ssl/schannel.cpp b/c/src/ssl/schannel.cpp
index 845db61..3056890 100644
--- a/c/src/ssl/schannel.cpp
+++ b/c/src/ssl/schannel.cpp
@@ -43,6 +43,7 @@
#include <proton/engine.h>
#include <assert.h>
+#include <stdio.h>
// security.h needs to see this to distinguish from kernel use.
#include <windows.h>
@@ -758,7 +759,7 @@ bool pn_ssl_get_cipher_name(pn_ssl_t *ssl0, char *buffer, size_t size )
SecPkgContext_ConnectionInfo info;
if (QueryContextAttributes(&ssl->ctxt_handle, SECPKG_ATTR_CONNECTION_INFO, &info) == SEC_E_OK) {
// TODO: come up with string for all permutations?
- pni_snprintf( buffer, size, "%x_%x:%x_%x:%x_%x",
+ snprintf( buffer, size, "%x_%x:%x_%x:%x_%x",
info.aiExch, info.dwExchStrength,
info.aiCipher, info.dwCipherStrength,
info.aiHash, info.dwHashStrength);
@@ -776,12 +777,12 @@ bool pn_ssl_get_protocol_name(pn_ssl_t *ssl0, char *buffer, size_t size )
SecPkgContext_ConnectionInfo info;
if (QueryContextAttributes(&ssl->ctxt_handle, SECPKG_ATTR_CONNECTION_INFO, &info) == SEC_E_OK) {
if (info.dwProtocol & (SP_PROT_TLS1_CLIENT | SP_PROT_TLS1_SERVER))
- pni_snprintf(buffer, size, "%s", "TLSv1");
+ snprintf(buffer, size, "%s", "TLSv1");
// TLSV1.1 and TLSV1.2 are supported as of XP-SP3, but not defined until VS2010
else if ((info.dwProtocol & 0x300))
- pni_snprintf(buffer, size, "%s", "TLSv1.1");
+ snprintf(buffer, size, "%s", "TLSv1.1");
else if ((info.dwProtocol & 0xC00))
- pni_snprintf(buffer, size, "%s", "TLSv1.2");
+ snprintf(buffer, size, "%s", "TLSv1.2");
else {
ssl_log_error("unexpected protocol %x", info.dwProtocol);
return false;
diff --git a/c/tests/fuzz/CMakeLists.txt b/c/tests/fuzz/CMakeLists.txt
index 2fd19b9..d84a250 100644
--- a/c/tests/fuzz/CMakeLists.txt
+++ b/c/tests/fuzz/CMakeLists.txt
@@ -77,17 +77,13 @@ pn_add_fuzz_test (fuzz-message-decode fuzz-message-decode.c)
target_link_libraries (fuzz-message-decode ${FUZZING_QPID_PROTON_CORE_LIBRARY})
# pn_url_parse is not in proton core and is only used by messenger so compile specially
-set(platform_MSVC ${PN_C_SOURCE_DIR}/compiler/msvc/snprintf.c)
-set(platform ${platform_${CMAKE_C_COMPILER_ID}})
-
pn_add_fuzz_test (fuzz-url
fuzz-url.c
${PN_C_SOURCE_DIR}/extra/url.c
${PN_C_SOURCE_DIR}/core/object/object.c
${PN_C_SOURCE_DIR}/core/object/string.c
${PN_C_SOURCE_DIR}/core/util.c
- ${PN_C_SOURCE_DIR}/core/memory.c
- ${platform})
+ ${PN_C_SOURCE_DIR}/core/memory.c)
target_compile_definitions(fuzz-url PRIVATE PROTON_DECLARE_STATIC)
# This regression test can take a very long time so don't run by default
diff --git a/python/setup.py.in b/python/setup.py.in
index ab064b4..b7106bd 100644
--- a/python/setup.py.in
+++ b/python/setup.py.in
@@ -137,7 +137,6 @@ class Configure(build_ext):
if self.compiler_type=='msvc':
sources += [
- os.path.join(proton_src, 'compiler', 'msvc', 'snprintf.c'),
os.path.join(proton_src, 'compiler', 'msvc', 'start.c')
]
elif self.compiler_type=='unix':
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org