Skip to content

Conversation

@sprintersb
Copy link

There are several places where suspect len arguments to strncat are specified, like for example in mylib/gdef.c::gdef_GetHostName():

   strncat (machine, ", ", (size_t) 2);

The semantics of strncat is that it writes at most 2 chars from ", " plus an additional terminating '\0' as needed. This is 3 chars, presumably what the authors intended. The obvious approach here would be to just use strcat for small static strings like in the sample, though the patch keeps the current coding style with strncat.

* mylib/gdef.c (gdef_GetHostName): Use proper len specification in strncat calls, i.e. pass the size of the source rather than the length.
* testu01/ubrent.c (ubrent_CreateXorgen64): Same.
* testu01/ulec.c (ulec_CreateMRG31k3p): Same.
* testu01/unif01.c (unif01_CreateLacGen,  unif01_CreateBiasGen) (unif01_CreateDoubleGen2, unif01_CreateDoubleGen): Same.
* testu01/svaria.c (svaria_SumLogs, svaria_WeightDistrib) (svaria_CollisionArgMax_00, svaria_SumCollector): When writing to chaine[], use the length of chaine[], i.e. LEN1 in strncat, instead of LEN2 which exceeds the length of chaine[].

There are several places where suspect len arguments to strncat are
specified, like for example in mylib/gdef.c::gdef_GetHostName():

	   strncat (machine, ", ", (size_t) 2);

The semantics of strncat is that it writes at most 2 chars from ", "
*plus* an additional terminating '\0' as needed.  This is 3 chars,
presumably what the authors intended.  The obvious approach here
would be to just use strcat for small static strings like in the
sample, though the patch keeps the current coding style with strncat.

	* mylib/gdef.c (gdef_GetHostName): Use proper len specification
	in strncat calls, i.e. pass the size of the source rather than
	the length.
	* testu01/ubrent.c (ubrent_CreateXorgen64): Same.
	* testu01/ulec.c (ulec_CreateMRG31k3p): Same.
	* testu01/unif01.c (unif01_CreateLacGen,  unif01_CreateBiasGen)
	(unif01_CreateDoubleGen2, unif01_CreateDoubleGen): Same.
	* testu01/svaria.c (svaria_SumLogs, svaria_WeightDistrib)
	(svaria_CollisionArgMax_00, svaria_SumCollector):
	When writing to chaine[], use the length of chaine[],
	i.e. LEN1 in strncat, instead of LEN2 which exceeds the
	length of chaine[].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant