* [PATCH v2 1/1] Pass "err" argument by address to "_nsError" function
@ 2025-02-18 13:27 Hazem Mohamed Abuelfotoh
2025-02-18 13:56 ` Pratyush Yadav
0 siblings, 1 reply; 2+ messages in thread
From: Hazem Mohamed Abuelfotoh @ 2025-02-18 13:27 UTC (permalink / raw)
To: dhowells, keyrings; +Cc: benh, Hazem Mohamed Abuelfotoh, Pratyush Yadav
Commit 0d71523ab584 (“DNS: Support AFS SRV records and
cell db config files”) has refactored the "nsError" function
by moving some of error handling to "_nsError" function
however we are passing the "err" argument to "_nsError"
by value not by address which is wrong as that basically
waste any processing we do in the "_nsError" function
so correcting that by passing "err" by address.
Reported-by: Pratyush Yadav <ptyadav@amazon.com>
Signed-off-by: Hazem Mohamed Abuelfotoh <abuehaze@amazon.com>
---
Changes v1 -> v2:
- Modify switch conditions to set timeouts correctly based on converted error codes
dns.afsdb.c | 4 ++--
key.dns.h | 2 +-
key.dns_resolver.c | 25 ++++++++++++-------------
3 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/dns.afsdb.c b/dns.afsdb.c
index 986c0f3..7bffb60 100644
--- a/dns.afsdb.c
+++ b/dns.afsdb.c
@@ -228,7 +228,7 @@ static int dns_query_AFSDB(const char *cell)
if (response_len < 0) {
/* negative result */
- _nsError(h_errno, cell);
+ _nsError(&h_errno, cell);
return -1;
}
@@ -267,7 +267,7 @@ static int dns_query_VL_SRV(const char *cell)
if (response_len < 0) {
/* negative result */
- _nsError(h_errno, cell);
+ _nsError(&h_errno, cell);
return -1;
}
diff --git a/key.dns.h b/key.dns.h
index 33d0ab3..2fedbc3 100644
--- a/key.dns.h
+++ b/key.dns.h
@@ -59,7 +59,7 @@ extern __attribute__((format(printf, 1, 2)))
void info(const char *fmt, ...);
extern __attribute__((noreturn))
void nsError(int err, const char *domain);
-extern void _nsError(int err, const char *domain);
+extern void _nsError(int *err, const char *domain);
extern __attribute__((format(printf, 1, 2)))
void debug(const char *fmt, ...);
diff --git a/key.dns_resolver.c b/key.dns_resolver.c
index 7a7ec42..0fe77b5 100644
--- a/key.dns_resolver.c
+++ b/key.dns_resolver.c
@@ -157,19 +157,20 @@ static const int ns_errno_map[] = {
[NO_DATA] = ENODATA,
};
-void _nsError(int err, const char *domain)
+void _nsError(int *err, const char *domain)
{
if (isatty(2))
- fprintf(stderr, "NS:%s: %s.\n", domain, hstrerror(err));
+ fprintf(stderr, "NS:%s: %s.\n", domain, hstrerror(*err));
else
- syslog(LOG_INFO, "%s: %s", domain, hstrerror(err));
+ syslog(LOG_INFO, "%s: %s", domain, hstrerror(*err));
- if (err >= sizeof(ns_errno_map) / sizeof(ns_errno_map[0]))
- err = ECONNREFUSED;
- else
- err = ns_errno_map[err];
+ if (*err >= sizeof(ns_errno_map) / sizeof(ns_errno_map[0]))
+ *err = ECONNREFUSED;
+ else{
+ *err = ns_errno_map[*err];
+ }
- info("Reject the key with error %d", err);
+ info("Reject the key with error %d", *err);
}
void nsError(int err, const char *domain)
@@ -177,14 +178,12 @@ void nsError(int err, const char *domain)
unsigned timeout;
int ret;
- _nsError(err, domain);
-
+ _nsError(&err, domain);
switch (err) {
- case TRY_AGAIN:
+ case EAGAIN:
timeout = 1;
break;
- case 0:
- case NO_RECOVERY:
+ case ECONNREFUSED:
timeout = 10;
break;
default:
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 1/1] Pass "err" argument by address to "_nsError" function
2025-02-18 13:27 [PATCH v2 1/1] Pass "err" argument by address to "_nsError" function Hazem Mohamed Abuelfotoh
@ 2025-02-18 13:56 ` Pratyush Yadav
0 siblings, 0 replies; 2+ messages in thread
From: Pratyush Yadav @ 2025-02-18 13:56 UTC (permalink / raw)
To: Hazem Mohamed Abuelfotoh; +Cc: dhowells, keyrings, benh, Pratyush Yadav
On Tue, Feb 18 2025, Hazem Mohamed Abuelfotoh wrote:
> Commit 0d71523ab584 (“DNS: Support AFS SRV records and
> cell db config files”) has refactored the "nsError" function
> by moving some of error handling to "_nsError" function
> however we are passing the "err" argument to "_nsError"
> by value not by address which is wrong as that basically
> waste any processing we do in the "_nsError" function
> so correcting that by passing "err" by address.
>
> Reported-by: Pratyush Yadav <ptyadav@amazon.com>
> Signed-off-by: Hazem Mohamed Abuelfotoh <abuehaze@amazon.com>
Acked-by: Pratyush Yadav <ptyadav@amazon.de>
--
Regards,
Pratyush Yadav
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-18 13:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-18 13:27 [PATCH v2 1/1] Pass "err" argument by address to "_nsError" function Hazem Mohamed Abuelfotoh
2025-02-18 13:56 ` Pratyush Yadav
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.