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 posted: [PATCH] gshadow: Matching sgetsgent, sgetsgent_r ERANGE handling (bug 30151) <https://sourceware.org/pipermail/libc-alpha/2023-February/145752.html>