1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-22 22:03:43 +03:00

Merge pull request #21944 from yuwata/nss-systemd-fix-pointer

nss-systemd: fix pointer calculation
This commit is contained in:
Yu Watanabe 2022-01-03 05:32:05 +09:00 committed by GitHub
commit 63e10c0cd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -39,10 +39,8 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
const char *canonical = NULL;
int n_addresses = 0;
uint32_t local_address_ipv4;
struct local_address *a;
size_t l, idx, ms;
char *r_name;
unsigned n;
PROTECT_ERRNO;
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
@ -136,7 +134,9 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
}
/* Fourth, fill actual addresses in, but in backwards order */
for (a = addresses + n_addresses - 1, n = 0; (int) n < n_addresses; n++, a--) {
for (int i = n_addresses; i > 0; i--) {
struct local_address *a = addresses + i - 1;
r_tuple = (struct gaih_addrtuple*) (buffer + idx);
r_tuple->next = r_tuple_prev;
r_tuple->name = r_name;

View File

@ -238,7 +238,7 @@ static enum nss_status copy_synthesized_group(
required += strlen(src->gr_passwd) + 1;
required += sizeof(char*); /* ...but that NULL still needs to be stored into the buffer! */
if (buflen < required) {
if (buflen < ALIGN(required)) {
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
@ -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 **) stpcpy(dest->gr_passwd, src->gr_passwd) + 1;
dest->gr_mem = ALIGN_PTR(stpcpy(dest->gr_passwd, src->gr_passwd) + 1);
*dest->gr_mem = NULL;
return NSS_STATUS_SUCCESS;