[2/4] nscd: Do not send missing not-found response in addgetnetgrentX (bug 31678)

Message ID 90f1fccc39a22663a5c57c4e7c938480ada61d87.1713974801.git.fweimer@redhat.com
State Superseded
Headers
Series Various nscd security fixes |

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

Commit Message

Florian Weimer April 24, 2024, 4:08 p.m. UTC
  If we failed to add a not-found response to the cache, the dataset
point can be null, resulting in a null pointer dereference.
---
 nscd/netgroupcache.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
  

Comments

Siddhesh Poyarekar April 24, 2024, 4:35 p.m. UTC | #1
On 2024-04-24 12:08, Florian Weimer wrote:
> If we failed to add a not-found response to the cache, the dataset
> point can be null, resulting in a null pointer dereference.
> ---

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

>   nscd/netgroupcache.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
> index 24fbac7668..8709fb77b6 100644
> --- a/nscd/netgroupcache.c
> +++ b/nscd/netgroupcache.c
> @@ -147,7 +147,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
>         /* No such service.  */
>         cacheable = do_notfound (db, fd, req, key, &dataset, &total, &timeout,
>   			       &key_copy);
> -      goto writeout;
> +      goto maybe_cache_add;
>       }
>   
>     memset (&data, '\0', sizeof (data));
> @@ -348,7 +348,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
>       {
>         cacheable = do_notfound (db, fd, req, key, &dataset, &total, &timeout,
>   			       &key_copy);
> -      goto writeout;
> +      goto maybe_cache_add;
>       }
>   
>     total = buffilled;
> @@ -410,14 +410,12 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
>     }
>   
>     if (he == NULL && fd != -1)
> -    {
> -      /* We write the dataset before inserting it to the database
> -	 since while inserting this thread might block and so would
> -	 unnecessarily let the receiver wait.  */
> -    writeout:
> +    /* We write the dataset before inserting it to the database since
> +       while inserting this thread might block and so would
> +       unnecessarily let the receiver wait.  */
>         writeall (fd, &dataset->resp, dataset->head.recsize);
> -    }
>   
> + maybe_cache_add:
>     if (cacheable)
>       {
>         /* If necessary, we also propagate the data to disk.  */
  

Patch

diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index 24fbac7668..8709fb77b6 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -147,7 +147,7 @@  addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
       /* No such service.  */
       cacheable = do_notfound (db, fd, req, key, &dataset, &total, &timeout,
 			       &key_copy);
-      goto writeout;
+      goto maybe_cache_add;
     }
 
   memset (&data, '\0', sizeof (data));
@@ -348,7 +348,7 @@  addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
     {
       cacheable = do_notfound (db, fd, req, key, &dataset, &total, &timeout,
 			       &key_copy);
-      goto writeout;
+      goto maybe_cache_add;
     }
 
   total = buffilled;
@@ -410,14 +410,12 @@  addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
   }
 
   if (he == NULL && fd != -1)
-    {
-      /* We write the dataset before inserting it to the database
-	 since while inserting this thread might block and so would
-	 unnecessarily let the receiver wait.  */
-    writeout:
+    /* We write the dataset before inserting it to the database since
+       while inserting this thread might block and so would
+       unnecessarily let the receiver wait.  */
       writeall (fd, &dataset->resp, dataset->head.recsize);
-    }
 
+ maybe_cache_add:
   if (cacheable)
     {
       /* If necessary, we also propagate the data to disk.  */