]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nss-systemd: fix required buffer size calculation
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 30 Dec 2021 15:31:51 +0000 (00:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 30 Dec 2021 18:12:09 +0000 (03:12 +0900)
This also fixes the pointer assigned to the gr_mem element of struct group.

Fixes a bug introduced by 47fd7fa6c650d7a0ac41bc89747e3b866ffb9534.

Fixes #21935.

src/nss-systemd/nss-systemd.c

index 1840a0d50831163f63072496700b67cedd248a87..7aea3652c41abea17ab957a2b3acbfc0c41fd0df 100644 (file)
@@ -236,7 +236,7 @@ static enum nss_status copy_synthesized_group(
 
         required = strlen(src->gr_name) + 1;
         required += strlen(src->gr_passwd) + 1;
-        required += 1; /* ...but that NULL still needs to be stored into the buffer! */
+        required += sizeof(char*); /* ...but that NULL still needs to be stored into the buffer! */
 
         if (buflen < required) {
                 *errnop = ERANGE;
@@ -250,7 +250,7 @@ static enum nss_status copy_synthesized_group(
         /* String fields point into the user-provided buffer */
         dest->gr_name = buffer;
         dest->gr_passwd = stpcpy(dest->gr_name, src->gr_name) + 1;
-        dest->gr_mem = (char **) strcpy(dest->gr_passwd, src->gr_passwd) + 1;
+        dest->gr_mem = (char **) stpcpy(dest->gr_passwd, src->gr_passwd) + 1;
         *dest->gr_mem = NULL;
 
         return NSS_STATUS_SUCCESS;