[X2Go-Commits] [libx2goclient] 08/09: src/x2goclient-network-ssh.c: replace older code with x2goclient_str_to_int ().
git-admin at x2go.org
git-admin at x2go.org
Sat Apr 4 17:55:27 CEST 2020
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository libx2goclient.
commit 7a24c133398a7b8e17273ff51ee9887fb88f6444
Author: Mihai Moldovan <ionic at ionic.de>
Date: Sat Mar 28 09:42:20 2020 +0100
src/x2goclient-network-ssh.c: replace older code with x2goclient_str_to_int ().
---
src/x2goclient-network-ssh.c | 45 ++++++++++++++++++++++++--------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c
index a3762a1..0f72712 100644
--- a/src/x2goclient-network-ssh.c
+++ b/src/x2goclient-network-ssh.c
@@ -45,6 +45,7 @@
#include "x2goclient.h"
#include "x2goclient-network-ssh.h"
+#include "x2goclient-utils.h"
struct _X2GoClientNetworkOptionsSSH {
@@ -219,28 +220,32 @@ static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString *portsp
* In the worst case, portspec->str[1] will point to a terminating NULL
* character, but that's non-critical.
*/
- gchar *err_msg = NULL;
- errno = 0;
- int saved_errno = 0;
- long long conv = strtoll (portspec->str + 1, NULL, 10);
- saved_errno = errno;
-
- if (0 != saved_errno) {
- err_msg = "Not a valid number.";
- }
- else if ((1 << 16) <= conv) {
- err_msg = "Port specifier out of range: too big.";
- }
- else if (0 >= conv) {
- err_msg = "Port specifier out of range: negative or zero.";
+ _Bool conv_err = TRUE,
+ min_err = TRUE,
+ max_err = TRUE;
+ long long conv = x2goclient_str_to_int (portspec->str + 1, TRUE, 1, TRUE, ((1 << 16) - 1), NULL, &conv_err, &min_err, &max_err);
+
+ if (conv_err) {
+ if (min_err) {
+ g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_UNDERFLOW, "Port specifier too small to fit into long long type.");
+ }
+ else if (max_err) {
+ g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_OVERFLOW, "Port specifier too big to fit into long long type.");
+ }
+ else {
+ g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_NOT_NUMERIC, "Port specifier is not numeric.");
+ }
}
else {
- ret = conv;
- }
-
- if (err_msg) {
- g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV, err_msg);
- err_msg = NULL;
+ if (min_err) {
+ g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_NEGATIVE_ZERO, "Port specifier out of range: negative or zero.");
+ }
+ else if (max_err) {
+ g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_TOO_BIG, "Port specifier out of range: negative or zero.");
+ }
+ else {
+ ret = conv;
+ }
}
}
else {
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
More information about the x2go-commits
mailing list