[3/5] hurd: Fix calling vm_deallocate (NULL)

Message ID 20230625231751.404120-3-bugaevc@gmail.com
State Committed
Commit f84c3ceb0447477eb022cd5da6c8f27a705deae6
Headers
Series [1/5] htl: Let Mach place thread stacks |

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-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed

Commit Message

Sergey Bugaev June 25, 2023, 11:17 p.m. UTC
  Only call vm_deallocate when we do have the old buffer, and check for
unexpected errors.

Spotted while debugging a msgids/readdir issue on x86_64-gnu.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 sysdeps/mach/hurd/readdir64.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
  

Comments

Samuel Thibault July 2, 2023, 11:28 p.m. UTC | #1
Applied, thanks!

Sergey Bugaev, le lun. 26 juin 2023 02:17:49 +0300, a ecrit:
> Only call vm_deallocate when we do have the old buffer, and check for
> unexpected errors.
> 
> Spotted while debugging a msgids/readdir issue on x86_64-gnu.
> 
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
>  sysdeps/mach/hurd/readdir64.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/sysdeps/mach/hurd/readdir64.c b/sysdeps/mach/hurd/readdir64.c
> index 2c01ca22..2d946793 100644
> --- a/sysdeps/mach/hurd/readdir64.c
> +++ b/sysdeps/mach/hurd/readdir64.c
> @@ -64,9 +64,13 @@ __readdir64 (DIR *dirp)
>  	      /* The data was passed out of line, so our old buffer is no
>  		 longer useful.  Deallocate the old buffer and reset our
>  		 information for the new buffer.  */
> -	      __vm_deallocate (__mach_task_self (),
> -			       (vm_address_t) dirp->__data,
> -			       dirp->__allocation);
> +	      if (dirp->__data != NULL)
> +		{
> +		  err = __vm_deallocate (__mach_task_self (),
> +					 (vm_address_t) dirp->__data,
> +					 dirp->__allocation);
> +		  assert_perror (err);
> +		}
>  	      dirp->__data = data;
>  	      dirp->__allocation = round_page (dirp->__size);
>  	    }
> -- 
> 2.41.0
> 
>
  

Patch

diff --git a/sysdeps/mach/hurd/readdir64.c b/sysdeps/mach/hurd/readdir64.c
index 2c01ca22..2d946793 100644
--- a/sysdeps/mach/hurd/readdir64.c
+++ b/sysdeps/mach/hurd/readdir64.c
@@ -64,9 +64,13 @@  __readdir64 (DIR *dirp)
 	      /* The data was passed out of line, so our old buffer is no
 		 longer useful.  Deallocate the old buffer and reset our
 		 information for the new buffer.  */
-	      __vm_deallocate (__mach_task_self (),
-			       (vm_address_t) dirp->__data,
-			       dirp->__allocation);
+	      if (dirp->__data != NULL)
+		{
+		  err = __vm_deallocate (__mach_task_self (),
+					 (vm_address_t) dirp->__data,
+					 dirp->__allocation);
+		  assert_perror (err);
+		}
 	      dirp->__data = data;
 	      dirp->__allocation = round_page (dirp->__size);
 	    }