[PATCH] Bugfix for OpenWrt package umdns
MRoeder at metz-connect.com
MRoeder at metz-connect.com
Fri Jan 21 03:37:14 PST 2022
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 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;
More information about the openwrt-devel
mailing list