Skip to content

Commit 35345b7

Browse files
committed
SSH crash when started with specific arguments /usr/sbin/sshd -T -C user=root -C host=nd-e013 -C addr=127.0.0.1 -C lport=22
Signed-off-by: Asha Behera <asha.behera@broadcom.com>
1 parent 7a69613 commit 35345b7

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
From 51b3d58afef6796fe0568deb4c3765e24cc828c9 Mon Sep 17 00:00:00 2001
2-
From: liuh-80 <liuh@microsoft.com>
3-
Date: Fri, 30 Sep 2022 16:57:03 +0800
4-
Subject: [PATCH] Export remote info for authorization. authorization.
1+
From 27402e9ed5de5e957ef0084d4f6dd6a62a2534ee Mon Sep 17 00:00:00 2001
2+
From: ab952469 <asha.behera@broadcom.com>
3+
Date: Sun, 30 Mar 2025 07:59:03 -0700
4+
Subject: [PATCH] [PATCH] Export remote info for authorization. authorization.
55

66
---
7-
auth.c | 11 +++++++++++
7+
auth.c | 14 ++++++++++++++
88
auth.h | 3 +++
99
session.c | 3 +++
10-
sshd.c | 5 +++++
11-
4 files changed, 22 insertions(+)
10+
sshd.c | 3 +++
11+
4 files changed, 23 insertions(+)
1212

1313
diff --git a/auth.c b/auth.c
14-
index c3693ba3f..96d551922 100644
14+
index 88578ec..2c64ee7 100644
1515
--- a/auth.c
1616
+++ b/auth.c
17-
@@ -764,3 +764,14 @@ auth_authorise_keyopts(struct ssh *ssh, struct passwd *pw,
18-
fatal_f("failed to restrict session");
19-
sshauthopt_free(restricted);
17+
@@ -1103,3 +1103,17 @@ auth_authorise_keyopts(struct ssh *ssh, struct passwd *pw,
18+
19+
return 0;
2020
}
2121
+
2222
+/* Export remote IP address and port for authorization. */
2323
+void
2424
+export_remote_info(struct ssh *ssh)
2525
+{
26-
+ const char *remote_ip = ssh_remote_ipaddr(ssh);
27-
+ const int remote_port = ssh_remote_port(ssh);
28-
+ const char remote_addr_port[32 + INET6_ADDRSTRLEN];
29-
+ snprintf(remote_addr_port, sizeof(remote_addr_port), "%s %d", remote_ip, remote_port);
30-
+ setenv("SSH_CLIENT_IPADDR_PORT", remote_addr_port, 1);
26+
+ if (ssh != NULL)
27+
+ {
28+
+ const char *remote_ip = ssh_remote_ipaddr(ssh);
29+
+ const int remote_port = ssh_remote_port(ssh);
30+
+ const char remote_addr_port[32 + INET6_ADDRSTRLEN];
31+
+ snprintf(remote_addr_port, sizeof(remote_addr_port), "%s %d", remote_ip, remote_port);
32+
+ setenv("SSH_CLIENT_IPADDR_PORT", remote_addr_port, 1);
33+
+ }
3134
+}
32-
\ No newline at end of file
3335
diff --git a/auth.h b/auth.h
34-
index 3cfce0eaf..3a34742b1 100644
36+
index 5da9fe7..95483ac 100644
3537
--- a/auth.h
3638
+++ b/auth.h
37-
@@ -229,6 +229,9 @@ struct passwd *fakepw(void);
39+
@@ -234,6 +234,9 @@ pid_t subprocess(const char *, struct passwd *,
3840

3941
int sys_auth_passwd(struct ssh *, const char *);
4042

@@ -45,10 +47,10 @@ index 3cfce0eaf..3a34742b1 100644
4547
krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
4648
#endif
4749
diff --git a/session.c b/session.c
48-
index a638ceef1..c615cb3d0 100644
50+
index 4128d26..3fa7c02 100644
4951
--- a/session.c
5052
+++ b/session.c
51-
@@ -619,6 +619,9 @@ do_exec_pty(struct ssh *ssh, Session *s, const char *command)
53+
@@ -624,6 +624,9 @@ do_exec_pty(struct ssh *ssh, Session *s, const char *command)
5254
/* Close the extra descriptor for the pseudo tty. */
5355
close(ttyfd);
5456

@@ -59,19 +61,10 @@ index a638ceef1..c615cb3d0 100644
5961
#ifndef HAVE_OSF_SIA
6062
do_login(ssh, s, command);
6163
diff --git a/sshd.c b/sshd.c
62-
index 3ef0c1452..2f67a0304 100644
64+
index e894ad6..c276421 100644
6365
--- a/sshd.c
6466
+++ b/sshd.c
65-
@@ -1737,6 +1737,8 @@ main(int ac, char **av)
66-
test_flag = 2;
67-
break;
68-
case 'C':
69-
+ /* Export remote IP address and port for authorization. */
70-
+ export_remote_info(ssh);
71-
connection_info = get_connection_info(ssh, 0, 0);
72-
if (parse_server_match_testspec(connection_info,
73-
optarg) == -1)
74-
@@ -2252,6 +2254,9 @@ main(int ac, char **av)
67+
@@ -2196,6 +2196,9 @@ main(int ac, char **av)
7568
*/
7669
remote_ip = ssh_remote_ipaddr(ssh);
7770

@@ -82,5 +75,5 @@ index 3ef0c1452..2f67a0304 100644
8275
audit_connection_from(remote_ip, remote_port);
8376
#endif
8477
--
85-
2.35.1.windows.2
78+
2.7.4
8679

0 commit comments

Comments
 (0)