The sgetsgent function checks errno for ERANGE, but sgetsgent_r only returns ERANGE, but does not set errno to ERANGE. As a result, sgetsgent does not detect failure at all, and returns indicating success without filling in the struct sgrp result.
This bug is somewhat similar in effect as bug 20338, but the root cause is quite different.
Not labeling as a security bug because /etc/gshadow contents (to which this data relates) is trusted data.
[PATCH] gshadow: Matching sgetsgent, sgetsgent_r ERANGE handling (bug 30151)