[COMMITTED] linux: Fix __sem_check_add_mapping name length

Message ID 20210209174423.3577809-1-adhemerval.zanella@linaro.org
State Committed
Commit e99156816d5033ca9421c80f55c5c8e7fcd5082b
Headers
Series [COMMITTED] linux: Fix __sem_check_add_mapping name length |

Commit Message

Adhemerval Zanella Netto Feb. 9, 2021, 5:44 p.m. UTC
  Take in consideration the trailling NULL since sem_search uses
strcmp to compare entries.

Checked on x86_64-linux-gnu and powerpc-linux-gnu (where it triggered
a nptl/tst-sem7 regression).
---
 sysdeps/pthread/sem_routines.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Andreas Schwab Feb. 9, 2021, 6:44 p.m. UTC | #1
On Feb 09 2021, Adhemerval Zanella via Libc-alpha wrote:

> diff --git a/sysdeps/pthread/sem_routines.c b/sysdeps/pthread/sem_routines.c
> index ea7a445324..c2c8b54cd0 100644
> --- a/sysdeps/pthread/sem_routines.c
> +++ b/sysdeps/pthread/sem_routines.c
> @@ -72,6 +72,7 @@ __sem_check_add_mapping (const char *name, int fd, sem_t *existing)
>    size_t namelen = strlen (name);
>    if (namelen > NAME_MAX)
>      return SEM_FAILED;
> +  namelen += 1;

struct search_sem has only room for NAME_MAX.

Andreas.
  

Patch

diff --git a/sysdeps/pthread/sem_routines.c b/sysdeps/pthread/sem_routines.c
index ea7a445324..c2c8b54cd0 100644
--- a/sysdeps/pthread/sem_routines.c
+++ b/sysdeps/pthread/sem_routines.c
@@ -72,6 +72,7 @@  __sem_check_add_mapping (const char *name, int fd, sem_t *existing)
   size_t namelen = strlen (name);
   if (namelen > NAME_MAX)
     return SEM_FAILED;
+  namelen += 1;
 
   sem_t *result = SEM_FAILED;