Bugzilla – Attachment 2803 Details for
Bug 2562
CanonicalizeHostname causes duplicate LocalForward attempts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
don't record duplicate forwards
forward-dup.diff (text/plain), 2.71 KB, created by
Damien Miller
on 2016-04-05 15:31:52 AEST
(
hide
)
Description:
don't record duplicate forwards
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2016-04-05 15:31:52 AEST
Size:
2.71 KB
patch
obsolete
>diff --git a/misc.c b/misc.c >index f1c0a97..ee18a32 100644 >--- a/misc.c >+++ b/misc.c >@@ -1080,3 +1080,41 @@ unix_listener(const char *path, int backlog, int unlink_first) > } > return sock; > } >+ >+/* >+ * Compares two strings that maybe be NULL. Returns non-zero if strings >+ * are both NULL or are identical, returns zero otherwise. >+ */ >+static int >+strcmp_maybe_null(const char *a, const char *b) >+{ >+ if ((a == NULL && b != NULL) || (a != NULL && b == NULL)) >+ return 0; >+ if (a != NULL && strcmp(a, b) != 0) >+ return 0; >+ return 1; >+} >+ >+/* >+ * Compare two forwards, returning non-zero if they are identical or >+ * zero otherwise. >+ */ >+int >+forward_equals(const struct Forward *a, const struct Forward *b) >+{ >+ if (strcmp_maybe_null(a->listen_host, b->listen_host) == 0) >+ return 0; >+ if (a->listen_port != b->listen_port) >+ return 0; >+ if (strcmp_maybe_null(a->listen_path, b->listen_path) == 0) >+ return 0; >+ if (strcmp_maybe_null(a->connect_host, b->connect_host) == 0) >+ return 0; >+ if (a->connect_port != b->connect_port) >+ return 0; >+ if (strcmp_maybe_null(a->connect_path, b->connect_path) == 0) >+ return 0; >+ /* allocated_port and handle are not checked */ >+ return 1; >+} >+ >diff --git a/misc.h b/misc.h >index 1b81be8..868e035 100644 >--- a/misc.h >+++ b/misc.h >@@ -27,6 +27,8 @@ struct Forward { > int handle; /* Handle for dynamic listen ports */ > }; > >+int forward_equals(const struct Forward *, const struct Forward *); >+ > /* Common server and client forwarding options. */ > struct ForwardOptions { > int gateway_ports; /* Allow remote connects to forwarded ports. */ >diff --git a/readconf.c b/readconf.c >index 0e2e9e0..f407564 100644 >--- a/readconf.c >+++ b/readconf.c >@@ -284,10 +286,16 @@ add_local_forward(Options *options, const struct Forward *newfwd) > { > struct Forward *fwd; > extern uid_t original_real_uid; >+ int i; > > if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 && > newfwd->listen_path == NULL) > fatal("Privileged ports can only be forwarded by root."); >+ /* Don't add duplicates */ >+ for (i = 0; i < options->num_local_forwards; i++) { >+ if (forward_equals(newfwd, options->local_forwards + i)) >+ return; >+ } > options->local_forwards = xreallocarray(options->local_forwards, > options->num_local_forwards + 1, > sizeof(*options->local_forwards)); >@@ -310,7 +318,13 @@ void > add_remote_forward(Options *options, const struct Forward *newfwd) > { > struct Forward *fwd; >+ int i; > >+ /* Don't add duplicates */ >+ for (i = 0; i < options->num_remote_forwards; i++) { >+ if (forward_equals(newfwd, options->remote_forwards + i)) >+ return; >+ } > options->remote_forwards = xreallocarray(options->remote_forwards, > options->num_remote_forwards + 1, > sizeof(*options->remote_forwards));
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
dtucker
:
ok+
Actions:
View
|
Diff
Attachments on
bug 2562
: 2803