void-packages/srcpkgs/pwnat/patches/fix_argument_parsing.diff
Đoàn Trần Công Danh 49cb564d14 srcpkgs/p*: convert patches to -Np1
* par is kept at -Np0

```sh
git grep -l '^patch_args=-Np0' "srcpkgs/$1*/template" |
while read template; do
	for p in ${template%/template}/patches/*; do
		sed -i '
			\,^[+-][+-][+-] /dev/null,b
			/^[*-]\+ [0-9]\+\(,[0-9]\+\)\? [*-]\+$/b
			s,^[*][*][*] ,&a/,
			/^--- /{
				s,\(^--- \)\(./\)*,\1a/,
				s,[.-][Oo][Rr][Ii][Gg]\([	/]\),\1,
				s/[.-][Oo][Rr][Ii][Gg]$//
				s/[.]patched[.]\([^.]\)/.\1/
				h
			}
			/^+++ -/{
				g
				s/^--- a/+++ b/
				b
			}
			s,\(^+++ \)\(./\)*,\1b/,
		' "$p"
	done
	sed -i '/^patch_args=/d' $template
done
```
2021-06-20 13:17:29 +07:00

89 lines
2.3 KiB
Diff

From ef844e18aad75929bad415bbc633a760890501e8 Mon Sep 17 00:00:00 2001
From: timdiels <timdiels.m@gmail.com>
Date: Mon, 30 Sep 2013 18:27:13 +0200
Subject: [PATCH] Fixed bug in client argument parsing
e.g. pwnat -c 44444 a b 22
would recognise "b" as proxy port, and eventually crash with a segfault
---
udpclient.c | 45 ++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git udpclient.c udpclient.c
index a95ac50..0d23c0d 100644
--- a/udpclient.c
+++ b/udpclient.c
@@ -60,7 +60,20 @@ static void disconnect_and_remove_client(uint16_t id, list_t *clients,
fd_set *fds);
static void signal_handler(int sig);
-int udpclient(int argc, char *argv[])
+bool isnumber(const char* str) {
+ if (!str) {
+ return false;
+ }
+
+ char* end;
+ strtol(str, &end, 10);
+ return *end == '\0';
+}
+
+/*
+ * argv: [local ip] <local port> <proxy host> [proxy port] <remote host> <remote port>
+ */
+int udpclient(int argc, char* argv[])
{
char *lhost, *lport, *phost, *pport, *rhost, *rport;
list_t *clients;
@@ -72,7 +85,7 @@ int udpclient(int argc, char *argv[])
socket_t *udp_sock = NULL;
char data[MSG_MAX_LEN];
char addrstr[ADDRSTRLEN];
- char pport_s[6];
+ char pport_s[6] = "2222";
struct timeval curr_time;
struct timeval check_time;
@@ -89,29 +102,27 @@ int udpclient(int argc, char *argv[])
int ret;
int i;
- int icmp_sock = 0;
+ int icmp_sock = 0;
int timeexc = 0;
- struct sockaddr_in src, dest, rsrc;
- struct hostent *hp;
- uint32_t timeexc_ip;
+ struct sockaddr_in src, dest, rsrc;
+ struct hostent *hp;
+ uint32_t timeexc_ip;
signal(SIGINT, &signal_handler);
+ // Parse arguments
i = 0;
- if (index(argv[i], 58) || index(argv[i], 46))
- lhost = argv[i++];
- else
- lhost = NULL;
+ if (!isnumber(argv[i]))
+ lhost = argv[i++];
+ else
+ lhost = NULL;
lport = argv[i++];
phost = argv[i++];
- if (index(argv[i], 58) || index(argv[i], 46))
- {
- snprintf(pport_s, 5, "2222");
- pport = pport_s;
- }
- else
- pport = argv[i++];
+ if (isnumber(argv[i]))
+ pport = argv[i++];
+ else
+ pport = pport_s;
rhost = argv[i++];
rport = argv[i++];