From: Andrea Claudi <aclaudi@redhat.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, dsahern@gmail.com
Subject: [PATCH iproute2] ss: use freecon() instead of free() when appropriate
Date: Fri, 28 Jan 2022 11:53:58 +0100 [thread overview]
Message-ID: <db01fe572f2ecd8720debf06d2b263f93e5fd205.1643367186.git.aclaudi@redhat.com> (raw)
According to SELinux API, when resources are allocated using getpidcon()
of getfilecon(), they should be freed using freecon().
This commit makes ss use freecon() where appropriate, defining a stub
function executing a free() useful when iproute2 is compiled without
SELinux support.
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
---
misc/ss.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index b39f63fe..f7d36914 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -97,6 +97,11 @@ static int security_get_initial_context(char *name, char **context)
*context = NULL;
return -1;
}
+
+static void freecon(char *context)
+{
+ free(context);
+}
#endif
int preferred_family = AF_UNSPEC;
@@ -618,7 +623,7 @@ static void user_ent_hash_build(void)
snprintf(name + nameoff, sizeof(name) - nameoff, "%d/fd/", pid);
pos = strlen(name);
if ((dir1 = opendir(name)) == NULL) {
- free(pid_context);
+ freecon(pid_context);
continue;
}
@@ -667,9 +672,9 @@ static void user_ent_hash_build(void)
}
user_ent_add(ino, p, pid, fd,
pid_context, sock_context);
- free(sock_context);
+ freecon(sock_context);
}
- free(pid_context);
+ freecon(pid_context);
closedir(dir1);
}
closedir(dir);
@@ -4725,7 +4730,7 @@ static int netlink_show_one(struct filter *f,
getpidcon(pid, &pid_context);
out(" proc_ctx=%s", pid_context ? : "unavailable");
- free(pid_context);
+ freecon(pid_context);
}
if (show_details) {
--
2.34.1
reply other threads:[~2022-01-28 10:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=db01fe572f2ecd8720debf06d2b263f93e5fd205.1643367186.git.aclaudi@redhat.com \
--to=aclaudi@redhat.com \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).