fix order of error checking in libsepol
PATCH 1/1 fix order of error checking in libsepol
The following patch fixes a bug found by Coverity in libsepol:
In write.c, a check for items==0 is done after a goto out: if items!=1, resulting in dead code, and rc==-1 when items==0 (which I assume is not intended).
thanks,
-serge
write.c +3 -4
@@ -567,10 +567,9 @@ static int cond_write_av_list(policydb_t buf[0 ] =cpu_to_le32 (len); items =put_entry (buf,sizeof (uint32_t ),1 , fp); -if (items !=1 ) - goto out; -if (items ==0 ) { - rc =0 ; +if (items !=1 ) { +if (items ==0 ) + rc =0 ; goto out; }
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 16 lines · On Fri, 2005-08-12 at 14:22 -0500, [email protected] wrote:
The following patch fixes a bug found by Coverity in libsepol:
In write.c, a check for items==0 is done after a goto out: if items!=1, resulting in dead code, and rc==-1 when items==0 (which I assume is not intended).thanks,
-sergeIndex:
src/write.c
===================================================================write.c +0
-0@@ -567,10 +567,9 @@ static int cond_write_av_list(policydb_t buf[0 ] =cpu_to_le32 (len);
write.c static int cond_write_av_list(policydb_t · line 574
Quoted 10 lines
write.c +3
-4items =put_entry (buf,sizeof (uint32_t ),1 , fp); -if (items !=1 ) - goto out; -if (items ==0 ) { - rc =0 ; +if (items !=1 ) { +if (items ==0 ) + rc =0 ; goto out; }
Actually, I think what was intended here was:
if (items != 1)
goto out;
if (len == 0) {
rc = 0;
goto out;
}items is the number of successfully written items, so anything other than 1 at that point is indeed an error, whereas len may be 0, in which case we can skip the list loop (not that there is any harm in just falling through to it).
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.