Mailing List Archive

[PATCH] Avoiding Segmentation fault while p points to NULL.
Signed-off-by: krishnaiah bommu <krishnaiah.bommu@intel.com>
---
match.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/match.c b/match.c
index fcf6959..ab74211 100644
--- a/match.c
+++ b/match.c
@@ -251,7 +251,8 @@ match_user(const char *user, const char *host, const char *ipaddr,

pat = xstrdup(pattern);
p = strchr(pat, '@');
- *p++ = '\0';
+ if (p != NULL)
+ *p++ = '\0';

if ((ret = match_pattern(user, pat)) == 1)
ret = match_host_and_ip(host, ipaddr, p);
--
2.7.4

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH] Avoiding Segmentation fault while p points to NULL. [ In reply to ]
On 25.09.2019 10:55, krishnaiah bommu wrote:
> Signed-off-by: krishnaiah bommu <krishnaiah.bommu@intel.com>
> ---
> match.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/match.c b/match.c
> index fcf6959..ab74211 100644
> --- a/match.c
> +++ b/match.c
> @@ -251,7 +251,8 @@ match_user(const char *user, const char *host, const char *ipaddr,
>
> pat = xstrdup(pattern);
> p = strchr(pat, '@');
> - *p++ = '\0';
> + if (p != NULL)
> + *p++ = '\0';

This looks impossible; actually, this strchr call is redundant, I'd rather replaced it with

- p = strchr(pat, '@');
+ p = pat + (p - pattern);

>
> if ((ret = match_pattern(user, pat)) == 1)
> ret = match_host_and_ip(host, ipaddr, p);
>
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH] Avoiding Segmentation fault while p points to NULL. [ In reply to ]
Hi,

This patch doesn't make sense: the lines immediately before this are:

if ((p = strchr(pattern, '@')) == NULL)
return match_pattern(user, pattern);

so it's not possible for strchr(pat, '@') to return NULL here.

-d

On Wed, 25 Sep 2019, krishnaiah bommu wrote:

> Signed-off-by: krishnaiah bommu <krishnaiah.bommu@intel.com>
> ---
> match.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/match.c b/match.c
> index fcf6959..ab74211 100644
> --- a/match.c
> +++ b/match.c
> @@ -251,7 +251,8 @@ match_user(const char *user, const char *host, const char *ipaddr,
>
> pat = xstrdup(pattern);
> p = strchr(pat, '@');
> - *p++ = '\0';
> + if (p != NULL)
> + *p++ = '\0';
>
> if ((ret = match_pattern(user, pat)) == 1)
> ret = match_host_and_ip(host, ipaddr, p);
> --
> 2.7.4
>
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
>
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev