diff mbox series

Bugfix for OpenWrt package umdns

Message ID OF74C0E29A.86D43F23-ONC12587D1.003DAB67-C12587D1.003FD5C3@metz-connect.com
State Changes Requested
Delegated to: Daniel Golle
Headers show
Series Bugfix for OpenWrt package umdns | expand

Commit Message

MRoeder@metz-connect.com Jan. 21, 2022, 11:37 a.m. UTC
Hi John,

I would like to submit a patch for the OpenWrt package umdns. The patch 
fixes a bug in the cache.c functions cache_record_find() and 
cache_host_is_known(). In both functions, the last element of the AVL tree 
is systematically missed, which can lead to duplicate cache entries and 
lookup failures. The fix duplicates the correct AVL tree traversal 
approach of cache_dump_recursive().

PS: Appologies if this message has format issues. This is my first attempt 
to submit a patch to OpenWrt through our company IBM Notes infrastructure, 
please let me know if the message format is unsuitable.

Best regards,
  Martin

--------------------------------
Fix AVL tree traversal in cache_record_find() and cache_host_is_known():

The AVL tree traversal in both functions systematically misses the last
AVL tree element. This can lead to duplicate cache entries and lookup 
failures.

The fix duplicates the correct AVL tree traversal approach of 
cache_dump_recursive().

Signed-off-by: Martin Röder <mroeder@metz-connect.com>

                if (r->type != type)
                        continue;
 
@@ -227,13 +224,10 @@ cache_host_is_known(char *record)
 {
        struct cache_record *l = avl_find_element(&records, record, l, 
avl);
 
-       if (!l)
-               return 0;
-
-       while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, 
record)) {
+       while (l && !strcmp(l->record, record)) {
                struct cache_record *r = l;
 
-               l = avl_next_element(l, avl);
+               l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, 
avl) : NULL;
                if ((r->type != TYPE_A) && (r->type != TYPE_AAAA))
                        continue;
                return 1;

Comments

Daniel Golle Jan. 31, 2022, 12:24 a.m. UTC | #1
Hi Martin,

On Fri, Jan 21, 2022 at 12:37:14PM +0100, MRoeder@metz-connect.com wrote:
> Hi John,
> 
> I would like to submit a patch for the OpenWrt package umdns. The patch 
> fixes a bug in the cache.c functions cache_record_find() and 
> cache_host_is_known(). In both functions, the last element of the AVL tree 
> is systematically missed, which can lead to duplicate cache entries and 
> lookup failures. The fix duplicates the correct AVL tree traversal 
> approach of cache_dump_recursive().
> 
> PS: Appologies if this message has format issues. This is my first attempt 
> to submit a patch to OpenWrt through our company IBM Notes infrastructure, 
> please let me know if the message format is unsuitable.

I've tried fixing up the new-lines, but that alone didn't do the trick
as all the white-space has apparently been mangled by the MUA.
If you can't use git-send-email, please use git-format-patch and
include the resulting file as attachment.

Please also add a short commit title heading the commit message.

Apart from that: thank you for reaching out and fixing this!


Cheers


Daniel

> 
> Best regards,
>   Martin
> 
> --------------------------------
> Fix AVL tree traversal in cache_record_find() and cache_host_is_known():
> 
> The AVL tree traversal in both functions systematically misses the last
> AVL tree element. This can lead to duplicate cache entries and lookup 
> failures.
> 
> The fix duplicates the correct AVL tree traversal approach of 
> cache_dump_recursive().
> 
> Signed-off-by: Martin Röder <mroeder@metz-connect.com>
> 
> --- a/cache.c
> +++ b/cache.c
> @@ -191,13 +191,10 @@ cache_record_find(char *record, int type
>  {
>         struct cache_record *l = avl_find_element(&records, record, l, 
> avl);
>  
> -       if (!l)
> -               return NULL;
> -
> -       while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, 
> record)) {
> +       while (l && !strcmp(l->record, record)) {
>                 struct cache_record *r = l;
>  
> -               l = avl_next_element(l, avl);
> +               l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, 
> avl) : NULL;
>                 if (r->type != type)
>                         continue;
>  
> @@ -227,13 +224,10 @@ cache_host_is_known(char *record)
>  {
>         struct cache_record *l = avl_find_element(&records, record, l, 
> avl);
>  
> -       if (!l)
> -               return 0;
> -
> -       while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, 
> record)) {
> +       while (l && !strcmp(l->record, record)) {
>                 struct cache_record *r = l;
>  
> -               l = avl_next_element(l, avl);
> +               l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, 
> avl) : NULL;
>                 if ((r->type != TYPE_A) && (r->type != TYPE_AAAA))
>                         continue;
>                 return 1;
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
diff mbox series

Patch

--- a/cache.c
+++ b/cache.c
@@ -191,13 +191,10 @@  cache_record_find(char *record, int type
 {
        struct cache_record *l = avl_find_element(&records, record, l, 
avl);
 
-       if (!l)
-               return NULL;
-
-       while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, 
record)) {
+       while (l && !strcmp(l->record, record)) {
                struct cache_record *r = l;
 
-               l = avl_next_element(l, avl);
+               l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, 
avl) : NULL;