From 8dcd430104699091c06ae33545465321afcbb0fb Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Fri, 4 Oct 2013 14:55:58 -0400 Subject: [PATCH] Fix errors found by coverity --- libsemanage-rhat.patch | 37 ++++++++++++++++++++++--------------- libsemanage.spec | 5 ++++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/libsemanage-rhat.patch b/libsemanage-rhat.patch index 7f50fdc..9f6cf94 100644 --- a/libsemanage-rhat.patch +++ b/libsemanage-rhat.patch @@ -250,10 +250,10 @@ index 8823b1e..cfcd039 100644 hidden_def(semanage_seuser_set_sename) diff --git a/libsemanage/src/seusers_local.c b/libsemanage/src/seusers_local.c -index e7cf12c..c77be73 100644 +index e7cf12c..c9a9ab2 100644 --- a/libsemanage/src/seusers_local.c +++ b/libsemanage/src/seusers_local.c -@@ -8,27 +8,149 @@ typedef struct semanage_seuser record_t; +@@ -8,27 +8,156 @@ typedef struct semanage_seuser record_t; #include #include @@ -314,8 +314,8 @@ index e7cf12c..c77be73 100644 + char *proles = NULL; + char msg[1024]; + const char *sep = "-"; -+ -+ strcpy(msg,"login"); ++ int rc = -1; ++ strcpy(msg, "login"); + if (seuser) { + name = semanage_seuser_get_name(seuser); + sename = semanage_seuser_get_sename(seuser); @@ -328,17 +328,19 @@ index e7cf12c..c77be73 100644 + proles = semanage_user_roles(handle, psename); + } + if (audit_type != AUDIT_ROLE_REMOVE) { -+ if (!psename || strcmp(psename, sename) != 0) { -+ sprintf(msg,"%s%s%s",msg, sep,"sename"); ++ if (sename && (!psename || strcmp(psename, sename) != 0)) { ++ strcat(msg,sep); ++ strcat(msg,"sename"); + sep = ","; + } -+ if (!proles || strcmp(proles, roles) != 0) { -+ sprintf(msg,"%s%s%s",msg, sep,"role"); ++ if (roles && (!proles || strcmp(proles, roles) != 0)) { ++ strcat(msg,sep); ++ strcat(msg,"role"); + sep = ","; + } -+ if (!pmls || strcmp(pmls, mls) != 0) { -+ sprintf(msg,"%s%s%s",msg, sep,"range"); -+ sep = ","; ++ if (mls && (!pmls || strcmp(pmls, mls) != 0)) { ++ strcat(msg,sep); ++ strcat(msg,"range"); + } + } + @@ -346,15 +348,20 @@ index e7cf12c..c77be73 100644 + if (fd < 0) + { + /* If kernel doesn't support audit, bail out */ -+ if (errno == EINVAL || errno == EPROTONOSUPPORT || errno == EAFNOSUPPORT) -+ return 0; -+ return fd; ++ if (errno == EINVAL || errno == EPROTONOSUPPORT || errno == EAFNOSUPPORT) { ++ rc = 0; ++ goto err; ++ } ++ rc = fd; ++ goto err; + } + audit_log_semanage_message(fd, audit_type, NULL, msg, name, 0, sename, roles, mls, psename, proles, pmls, NULL, NULL,NULL, success); ++ rc = 0; ++err: + audit_close(fd); + free(roles); + free(proles); -+ return 0; ++ return rc; +} int semanage_seuser_modify_local(semanage_handle_t * handle, diff --git a/libsemanage.spec b/libsemanage.spec index 358550b..4ed2867 100644 --- a/libsemanage.spec +++ b/libsemanage.spec @@ -7,7 +7,7 @@ Summary: SELinux binary policy manipulation library Name: libsemanage Version: 2.1.10 -Release: 12%{?dist} +Release: 13%{?dist} License: LGPLv2+ Group: System Environment/Libraries Source: libsemanage-%{version}.tgz @@ -179,6 +179,9 @@ rm -rf ${RPM_BUILD_ROOT} %endif # if with_python3 %changelog +* Fri Oct 4 2013 Dan Walsh - 2.1.10-13 +- Fix errors found by coverity + * Wed Sep 25 2013 Dan Walsh - 2.1.10-12 - Do not fail on missing SELinux User Record when adding login record