nss: fix error to ERANGE for nss calls with too little buffer space (#5365)

This is a follow-up for #5359, fixing the error codes in a similar way
for the other NSS modules.

(user/group lookup calls don't have h_errnop, hence we don't update that
in those cases)
This commit is contained in:
Lennart Poettering 2017-02-16 21:29:09 +01:00 committed by Martin Pitt
parent 8acdd72120
commit cda458a54a
3 changed files with 17 additions and 17 deletions

View File

@ -114,8 +114,8 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
l = strlen(canonical);
ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * (n_addresses > 0 ? n_addresses : 2);
if (buflen < ms) {
*errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
@ -220,8 +220,8 @@ static enum nss_status fill_in_hostent(
(c > 0 ? c+1 : 2) * sizeof(char*);
if (buflen < ms) {
*errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}

View File

@ -151,8 +151,8 @@ enum nss_status _nss_mymachines_gethostbyname4_r(
l = strlen(name);
ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * c;
if (buflen < ms) {
*errnop = ENOMEM;
*h_errnop = TRY_AGAIN;
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
@ -306,8 +306,8 @@ enum nss_status _nss_mymachines_gethostbyname3_r(
ms = ALIGN(l+1) + c * ALIGN(alen) + (c+2) * sizeof(char*);
if (buflen < ms) {
*errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
@ -471,7 +471,7 @@ enum nss_status _nss_mymachines_getpwnam_r(
l = strlen(name);
if (buflen < l+1) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
@ -550,7 +550,7 @@ enum nss_status _nss_mymachines_getpwuid_r(
goto not_found;
if (snprintf(buffer, buflen, "vu-%s-" UID_FMT, machine, (uid_t) mapped) >= (int) buflen) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
@ -645,7 +645,7 @@ enum nss_status _nss_mymachines_getgrnam_r(
l = sizeof(char*) + strlen(name) + 1;
if (buflen < l) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
@ -722,13 +722,13 @@ enum nss_status _nss_mymachines_getgrgid_r(
goto not_found;
if (buflen < sizeof(char*) + 1) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
memzero(buffer, sizeof(char*));
if (snprintf(buffer + sizeof(char*), buflen - sizeof(char*), "vg-%s-" GID_FMT, machine, (gid_t) mapped) >= (int) buflen) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}

View File

@ -185,7 +185,7 @@ enum nss_status _nss_systemd_getpwnam_r(
l = strlen(name);
if (buflen < l+1) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
@ -286,7 +286,7 @@ enum nss_status _nss_systemd_getpwuid_r(
l = strlen(translated) + 1;
if (buflen < l) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
@ -386,7 +386,7 @@ enum nss_status _nss_systemd_getgrnam_r(
l = sizeof(char*) + strlen(name) + 1;
if (buflen < l) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
@ -484,7 +484,7 @@ enum nss_status _nss_systemd_getgrgid_r(
l = sizeof(char*) + strlen(translated) + 1;
if (buflen < l) {
*errnop = ENOMEM;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}