[2/3] nss: Improve network file parser (bz 32573)
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
Avoid malloca because /etc/networks lines can be arbitrarily long.
Instead of handcrafting the input for inet_network by adding ".0"
octets if they are missing, just left shift the result.
Also do not accept invalid entries, but ignore the line instead.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
nss/nss_files/files-network.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
--
2.48.1
Comments
On 19/01/25 12:04, Tobias Stoeckmann wrote:
> Avoid malloca because /etc/networks lines can be arbitrarily long.
> Instead of handcrafting the input for inet_network by adding ".0"
> octets if they are missing, just left shift the result.
>
> Also do not accept invalid entries, but ignore the line instead.
>
> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
The patch looks good, although I think it should be squashed with the rest
the series.
> ---
> nss/nss_files/files-network.c | 20 ++++++--------------
> 1 file changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
> index ca94372024..f08daaf55f 100644
> --- a/nss/nss_files/files-network.c
> +++ b/nss/nss_files/files-network.c
> @@ -42,7 +42,8 @@ LINE_PARSER
>
> STRING_FIELD (addr, isspace, 1);
> /* 'inet_network' does not add zeroes at the end if the network number
> - does not four byte values. We add them ourselves if necessary. */
> + does not contain four byte values. We shift result ourselves if
> + necessary. */
> cp = strchr (addr, '.');
> if (cp != NULL)
> {
> @@ -56,20 +57,11 @@ LINE_PARSER
> ++n;
> }
> }
> - if (n < 4)
> - {
> - char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1);
> - cp = stpcpy (newp, addr);
> - do
> - {
> - *cp++ = '.';
> - *cp++ = '0';
> - }
> - while (++n < 4);
> - *cp = '\0';
> - addr = newp;
> - }
> result->n_net = __inet_network (addr);
> + if (result->n_net == INADDR_NONE)
> + return 0;
> + if (n < 4)
> + result->n_net <<= 8 * (4 - n);
> result->n_addrtype = AF_INET;
>
> })
> --
> 2.48.1
>
@@ -42,7 +42,8 @@ LINE_PARSER
STRING_FIELD (addr, isspace, 1);
/* 'inet_network' does not add zeroes at the end if the network number
- does not four byte values. We add them ourselves if necessary. */
+ does not contain four byte values. We shift result ourselves if
+ necessary. */
cp = strchr (addr, '.');
if (cp != NULL)
{
@@ -56,20 +57,11 @@ LINE_PARSER
++n;
}
}
- if (n < 4)
- {
- char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1);
- cp = stpcpy (newp, addr);
- do
- {
- *cp++ = '.';
- *cp++ = '0';
- }
- while (++n < 4);
- *cp = '\0';
- addr = newp;
- }
result->n_net = __inet_network (addr);
+ if (result->n_net == INADDR_NONE)
+ return 0;
+ if (n < 4)
+ result->n_net <<= 8 * (4 - n);
result->n_addrtype = AF_INET;
})