nss-systemd: pack pw_passwd result into supplied buffer
authorMichael Catanzaro <mcatanzaro@redhat.com>
Wed, 8 Sep 2021 18:42:16 +0000 (13:42 -0500)
committerMichael Catanzaro <mcatanzaro@redhat.com>
Wed, 8 Sep 2021 21:19:28 +0000 (16:19 -0500)
commit92b264676ccd79c89da270aabc1ec466fa18cd0d
treeb58f3ae632a362d51b38088648d4f208ec97cfe6
parent9f6ef467818f902fe5369c8e37a39a3901bdcf4f
nss-systemd: pack pw_passwd result into supplied buffer

getpwnam_r() guarantees that the strings in the struct passwd that it
returns are pointers into the buffer allocated by the application and
passed to getpwnam_r(). This means applications may choose to modify the
strings in place, as long as the length of the strings is not increased.
So it's wrong for us to return a static string here, we really do have
to copy it into the application-provided buffer like we do for all the
other strings.

This is only a theoretical problem since it would be very weird for an
application to modify the pw_passwd field, but I spotted this when
investigating a similar crash caused by glib editing a different field.
See also:

https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2244
src/nss-systemd/userdb-glue.c