Don't set ret_namelen and ret_resnamelen in res_find() unless both the

corresponding pointer to the buffer (ret_name and ret_resname) is non-NULL
to avoid possible NULL pointer derefs.

Reported by:	Coverity via sam
This commit is contained in:
John Baldwin 2005-03-24 21:20:25 +00:00
parent 0440fc940a
commit 85c36f3d25
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=144077

View File

@ -174,7 +174,7 @@ res_find(int *line, int *startln,
if (ret_name)
*ret_name = s;
s = index(s, '.') + 1; /* start of unit */
if (ret_namelen)
if (ret_namelen && ret_name)
*ret_namelen = s - *ret_name - 1; /* device length */
if (ret_unit)
*ret_unit = r_unit;
@ -182,7 +182,7 @@ res_find(int *line, int *startln,
if (ret_resname)
*ret_resname = s;
s = index(s, '=') + 1; /* start of value */
if (ret_resnamelen)
if (ret_resnamelen && ret_resname)
*ret_resnamelen = s - *ret_resname - 1; /* value len */
if (ret_value)
*ret_value = s;