Prevent potentially unterminated buffers while adding rule to the list
authorRafal Krypa <r.krypa@samsung.com>
Fri, 16 Aug 2013 08:48:56 +0000 (10:48 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Fri, 16 Aug 2013 08:51:52 +0000 (10:51 +0200)
commit2aa62498600a3ca04ad0cedb3a07c6143aae29a2
treef7231dfa8ec37afef54ed5bbd996aa3450b90b8c
parent66811de97982341cb85da49aa92d6be37eab6615
Prevent potentially unterminated buffers while adding rule to the list

Functions smack_accesses_add() and smack_accesses_add_modify() don't check
length of arguments subject and object. These arguments are used as source
for strncpy(), which can cause labels to be truncated.

But the length argument for strncpy() is too large. This might cause
rule->subject or rule->object to be not terminated by null character.
It can happen when these functions are called from outside libsmack.
It can also happen while parsing files in smack_accesses_add_from_file(),
because that function doesn't validate subject and object too.

This commit fixes the problem by checking arguments in smack_accesses_add()
and smack_accesses_add_modify(). After checking strcpy() is safe for
copying them.
libsmack/libsmack.c