Attention is currently required from: Arne Schwabe, Frank Lichtenheld.
Hello Arne Schwabe, Răzvan Cojocaru,
I'd like you to reexamine a change. Please visit
https://gerrit.openvpn.net/c/openvpn/+/2168?usp=email
to look at the new patch set (#3).
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.
Change subject: console: Switch response_len to size_t
......................................................................
console: Switch response_len to size_t
We need some casts either way since the system
APIs are just too different. But overall it feels
cleaner when using size_t.
Change-Id: I1c87faefd3adc2d95b5318437d097c3970a120d3
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/console.c
M src/openvpn/console.h
M src/openvpn/console_builtin.c
M src/openvpn/console_systemd.c
M tests/unit_tests/openvpn/test_user_pass.c
7 files changed, 20 insertions(+), 47 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/68/2168/3
diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index e672b74..c60936a 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -576,9 +576,9 @@
* like buf_null_terminate, but operate on strings
*/
void
-string_null_terminate(char *str, int len, int capacity)
+string_null_terminate(char *str, size_t len, size_t capacity)
{
- ASSERT(len >= 0 && len <= capacity && capacity > 0);
+ ASSERT(len <= capacity && capacity > 0);
if (len < capacity)
{
*(str + len) = '\0';
diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index ae6dcb7..541f0bd 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/buffer.h
@@ -872,7 +872,7 @@
* @param capacity Total size of the character buffer in bytes.
*/
#ifdef _WIN32
-void string_null_terminate(char *str, int len, int capacity);
+void string_null_terminate(char *str, size_t len, size_t capacity);
#endif
/**@}*/
/* End of string utility functions */
diff --git a/src/openvpn/console.c b/src/openvpn/console.c
index 78f445b..358b9ae 100644
--- a/src/openvpn/console.c
+++ b/src/openvpn/console.c
@@ -53,7 +53,7 @@
void
-query_user_add(char *prompt, char *resp, int resp_len, bool echo)
+query_user_add(char *prompt, char *resp, size_t resp_len, bool echo)
{
int i;
diff --git a/src/openvpn/console.h b/src/openvpn/console.h
index 89550ce..94b1032 100644
--- a/src/openvpn/console.h
+++ b/src/openvpn/console.h
@@ -32,10 +32,10 @@
*/
struct _query_user
{
- char *prompt; /**< Prompt to present to the user */
- char *response; /**< The user's response */
- int response_len; /**< Length the of the user response */
- bool echo; /**< True: The user should see what is being typed,
otherwise mask it */
+ char *prompt; /**< Prompt to present to the user */
+ char *response; /**< The user's response */
+ size_t response_len; /**< Length the of the user response */
+ bool echo; /**< True: The user should see what is being typed,
otherwise mask it */
};
#define QUERY_USER_NUMSLOTS 10
@@ -57,7 +57,7 @@
* @param echo Should the user input be echoed to the user? If False,
input will be masked
*
*/
-void query_user_add(char *prompt, char *resp, int resp_len, bool echo);
+void query_user_add(char *prompt, char *resp, size_t resp_len, bool echo);
/**
@@ -115,7 +115,7 @@
*
*/
static inline bool
-query_user_SINGLE(char *prompt, char *resp, int resp_len, bool echo)
+query_user_SINGLE(char *prompt, char *resp, size_t resp_len, bool echo)
{
query_user_clear();
query_user_add(prompt, resp, resp_len, echo);
diff --git a/src/openvpn/console_builtin.c b/src/openvpn/console_builtin.c
index 0353ade..8206d3d 100644
--- a/src/openvpn/console_builtin.c
+++ b/src/openvpn/console_builtin.c
@@ -41,11 +41,6 @@
#include <termios.h>
#endif
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
#ifdef _WIN32
#include "win32.h"
@@ -62,11 +57,11 @@
* exit event is signaled.
*/
static bool
-get_console_input_win32(const char *prompt, const bool echo, char *input,
const int capacity)
+get_console_input_win32(const char *prompt, const bool echo, char *input,
const size_t capacity)
{
ASSERT(prompt);
ASSERT(input);
- ASSERT(capacity > 0);
+ ASSERT(capacity > 0 && capacity < INT_MAX);
input[0] = '\0';
@@ -110,16 +105,16 @@
return false;
}
- status = ReadConsoleW(in, winput, capacity, &len, NULL);
- WideCharToMultiByte(CP_UTF8, 0, winput, len, input, capacity, NULL,
NULL);
+ status = ReadConsoleW(in, winput, (DWORD)capacity, &len, NULL);
+ WideCharToMultiByte(CP_UTF8, 0, winput, (int)len, input,
(int)capacity, NULL, NULL);
free(winput);
}
else
{
- status = ReadFile(in, input, capacity, &len, NULL);
+ status = ReadFile(in, input, (DWORD)capacity, &len, NULL);
}
- string_null_terminate(input, (int)len, capacity);
+ string_null_terminate(input, len, capacity);
chomp(input);
if (!echo)
@@ -191,11 +186,11 @@
* @returns Returns True if user input was gathered
*/
static bool
-get_console_input(const char *prompt, const bool echo, char *input, const int
capacity)
+get_console_input(const char *prompt, const bool echo, char *input, const
size_t capacity)
{
ASSERT(prompt);
ASSERT(input);
- ASSERT(capacity > 0);
+ ASSERT(capacity > 0 && capacity <= INT_MAX);
input[0] = '\0';
#ifdef _WIN32
@@ -238,7 +233,7 @@
restore_tty = (tcsetattr(fileno(fp), TCSAFLUSH, &tty_tmp) == 0);
}
- if (fgets(input, capacity, fp) != NULL)
+ if (fgets(input, (int)capacity, fp) != NULL)
{
chomp(input);
ret = true;
@@ -294,7 +289,3 @@
return ret;
}
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
diff --git a/src/openvpn/console_systemd.c b/src/openvpn/console_systemd.c
index 8fc7f72..f0ca7fa 100644
--- a/src/openvpn/console_systemd.c
+++ b/src/openvpn/console_systemd.c
@@ -53,13 +53,8 @@
return (sd_booted() > 0) && (stat(SYSTEMD_ASK_PASSWORD_PATH, &c) == 0);
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
static bool
-get_console_input_systemd(const char *prompt, const bool echo, char *input,
const int capacity)
+get_console_input_systemd(const char *prompt, const bool echo, char *input,
const size_t capacity)
{
int std_out;
bool ret = false;
@@ -91,10 +86,6 @@
return ret;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/**
* Systemd aware implementation of query_user_exec(). If systemd is not
running
* it will fall back to use query_user_exec_builtin() instead.
diff --git a/tests/unit_tests/openvpn/test_user_pass.c
b/tests/unit_tests/openvpn/test_user_pass.c
index 5bc1d2a..54b3617 100644
--- a/tests/unit_tests/openvpn/test_user_pass.c
+++ b/tests/unit_tests/openvpn/test_user_pass.c
@@ -47,11 +47,6 @@
}
#endif
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
bool
query_user_exec_builtin(void)
{
@@ -65,10 +60,6 @@
return mock();
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
void
management_auth_failure(const struct management *man, const char *type, const
char *reason)
{
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2168?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1c87faefd3adc2d95b5318437d097c3970a120d3
Gerrit-Change-Number: 2168
Gerrit-PatchSet: 3
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
Gerrit-Attention: Frank Lichtenheld <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel