]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Fix CID 1006692 in /usr/sbin/pw pw_log() function and other fixes
authortruckman <truckman@FreeBSD.org>
Tue, 24 May 2016 05:02:24 +0000 (05:02 +0000)
committertruckman <truckman@FreeBSD.org>
Tue, 24 May 2016 05:02:24 +0000 (05:02 +0000)
commit9f44a80b1c909e8f3ef2610a26e0798ffa7a5260
tree53cbcfc99797f74107d288a8d3e3198a6a01b097
parent1364d3218fce58d9c53fcde0d8f452228355d77b
Fix CID 1006692 in /usr/sbin/pw pw_log() function and other fixes

The length of the name returned from the $LOGNAME and $USER can be
very long and it was being concatenated to a fixed length buffer
with no bounds checking.  Fix this problem by limiting the length
of the name copied.

Additionally, this name is actually used to create a format string
to be used in adding log file entries so embedded % characters in
the name could confuse *printf(), and embedded whitespace could
confuse a log file parser.  Handle the former by escaping each %
with an additional %, and handle the latter by simply stripping it
out.

Clean up the code by moving the variable declarations to the top
of the function, formatting them to conform with style, and moving
intialization elsewhere.

Reduce code indentation by returning early in a couple of places.

Reported by: Coverity
CID: 1006692
Reviewed by: markj (previous version)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6490
usr.sbin/pw/pw_log.c