avoid xfree(NULL) in ssh_selinux_copy_context() (#789502)

This commit is contained in:
Petr Lautrbach 2012-11-05 16:37:05 +01:00
parent 466615c721
commit 9c823ca43b
1 changed files with 16 additions and 14 deletions

View File

@ -1,14 +1,14 @@
diff -up openssh-5.9p0/openbsd-compat/port-linux.c.sftp-chroot openssh-5.9p0/openbsd-compat/port-linux.c diff -up openssh-5.9p1/openbsd-compat/port-linux.c.sftp-chroot openssh-5.9p1/openbsd-compat/port-linux.c
--- openssh-5.9p0/openbsd-compat/port-linux.c.sftp-chroot 2011-09-01 04:12:22.743024608 +0200 --- openssh-5.9p1/openbsd-compat/port-linux.c.sftp-chroot 2012-11-05 16:32:23.932502573 +0100
+++ openssh-5.9p0/openbsd-compat/port-linux.c 2011-09-01 04:12:23.069088065 +0200 +++ openssh-5.9p1/openbsd-compat/port-linux.c 2012-11-05 16:34:28.383235006 +0100
@@ -503,6 +503,23 @@ ssh_selinux_change_context(const char *n @@ -503,6 +503,25 @@ ssh_selinux_change_context(const char *n
xfree(newctx); xfree(newctx);
} }
+void +void
+ssh_selinux_copy_context(void) +ssh_selinux_copy_context(void)
+{ +{
+ char *ctx; + security_context_t *ctx;
+ +
+ if (!ssh_selinux_enabled()) + if (!ssh_selinux_enabled())
+ return; + return;
@ -17,17 +17,19 @@ diff -up openssh-5.9p0/openbsd-compat/port-linux.c.sftp-chroot openssh-5.9p0/ope
+ logit("%s: getcon failed with %s", __func__, strerror (errno)); + logit("%s: getcon failed with %s", __func__, strerror (errno));
+ return; + return;
+ } + }
+ if (setcon(ctx) < 0) + if (ctx != NULL) {
+ logit("%s: setcon failed with %s", __func__, strerror (errno)); + if (setcon(ctx) < 0)
+ xfree(ctx); + logit("%s: setcon failed with %s", __func__, strerror (errno));
+ freecon(ctx);
+ }
+} +}
+ +
#endif /* WITH_SELINUX */ #endif /* WITH_SELINUX */
#ifdef LINUX_OOM_ADJUST #ifdef LINUX_OOM_ADJUST
diff -up openssh-5.9p0/openbsd-compat/port-linux.h.sftp-chroot openssh-5.9p0/openbsd-compat/port-linux.h diff -up openssh-5.9p1/openbsd-compat/port-linux.h.sftp-chroot openssh-5.9p1/openbsd-compat/port-linux.h
--- openssh-5.9p0/openbsd-compat/port-linux.h.sftp-chroot 2011-01-25 02:16:18.000000000 +0100 --- openssh-5.9p1/openbsd-compat/port-linux.h.sftp-chroot 2011-01-25 02:16:18.000000000 +0100
+++ openssh-5.9p0/openbsd-compat/port-linux.h 2011-09-01 04:12:23.163088777 +0200 +++ openssh-5.9p1/openbsd-compat/port-linux.h 2012-11-05 16:32:23.935502591 +0100
@@ -24,6 +24,7 @@ int ssh_selinux_enabled(void); @@ -24,6 +24,7 @@ int ssh_selinux_enabled(void);
void ssh_selinux_setup_pty(char *, const char *); void ssh_selinux_setup_pty(char *, const char *);
void ssh_selinux_setup_exec_context(char *); void ssh_selinux_setup_exec_context(char *);
@ -36,9 +38,9 @@ diff -up openssh-5.9p0/openbsd-compat/port-linux.h.sftp-chroot openssh-5.9p0/ope
void ssh_selinux_setfscreatecon(const char *); void ssh_selinux_setfscreatecon(const char *);
#endif #endif
diff -up openssh-5.9p0/session.c.sftp-chroot openssh-5.9p0/session.c diff -up openssh-5.9p1/session.c.sftp-chroot openssh-5.9p1/session.c
--- openssh-5.9p0/session.c.sftp-chroot 2011-09-01 04:12:19.698049195 +0200 --- openssh-5.9p1/session.c.sftp-chroot 2012-11-05 16:32:23.913502453 +0100
+++ openssh-5.9p0/session.c 2011-09-01 04:40:03.598148719 +0200 +++ openssh-5.9p1/session.c 2012-11-05 16:32:23.935502591 +0100
@@ -1519,6 +1519,9 @@ do_setusercontext(struct passwd *pw) @@ -1519,6 +1519,9 @@ do_setusercontext(struct passwd *pw)
pw->pw_uid); pw->pw_uid);
chroot_path = percent_expand(tmp, "h", pw->pw_dir, chroot_path = percent_expand(tmp, "h", pw->pw_dir,