[PATCH] Bugfix for OpenWrt package umdns

Daniel Golle daniel at makrotopia.org
Sun Jan 30 16:24:10 PST 2022


Hi Martin,

On Fri, Jan 21, 2022 at 12:37:14PM +0100, MRoeder at 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 at 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 at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list