Fix comparison between two character arrays

Message ID alpine.LRH.2.21.1807271051530.8599@petit.fibranet.lan
State Accepted
Commit 613a7f90361533fd5310ee836635a1e0864dfa71
Headers show
Series
  • Fix comparison between two character arrays
Related show

Commit Message

Jordi Sanfeliu July 27, 2018, 9:02 a.m.
Hello,

The member 'id' in the 'utmp' struct is not a numeric but a character 
array, hence the strncmp() function is needed to compare two members.


Thanks.

--
Jordi Sanfeliu
FIBRANET Network Services Provider
https://www.fibranet.cat

Comments

Corinna Vinschen July 30, 2018, 7:37 a.m. | #1
On Jul 27 11:02, Jordi Sanfeliu wrote:
> 

> Hello,

> 

> The member 'id' in the 'utmp' struct is not a numeric but a character array,

> hence the strncmp() function is needed to compare two members.

> 

> diff --git a/newlib/libc/unix/getut.c b/newlib/libc/unix/getut.c

> index 89ed739..71a8c8f 100644

> --- a/newlib/libc/unix/getut.c

> +++ b/newlib/libc/unix/getut.c

> @@ -63,7 +63,7 @@ getutid (struct utmp *id)

>  	case LOGIN_PROCESS:

>  	case USER_PROCESS:

>  	case DEAD_PROCESS:

> -	  if (id->ut_id == utmp_data.ut_id)

> +	  if (!strncmp (id->ut_id, utmp_data.ut_id, sizeof (utmp_data.ut_id)))

>  	    return &utmp_data;

>  	  break;

>  	default:

> 

> Thanks.

> 

> --

> Jordi Sanfeliu

> FIBRANET Network Services Provider

> https://www.fibranet.cat


Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

Patch

diff --git a/newlib/libc/unix/getut.c b/newlib/libc/unix/getut.c
index 89ed739..71a8c8f 100644
--- a/newlib/libc/unix/getut.c
+++ b/newlib/libc/unix/getut.c
@@ -63,7 +63,7 @@  getutid (struct utmp *id)
  	case LOGIN_PROCESS:
  	case USER_PROCESS:
  	case DEAD_PROCESS:
-	  if (id->ut_id == utmp_data.ut_id)
+	  if (!strncmp (id->ut_id, utmp_data.ut_id, sizeof (utmp_data.ut_id)))
  	    return &utmp_data;
  	  break;
  	default: