[PATCH][gdb] Improve early exits for env var in debuginfod-support.c

Tom de Vries tdevries@suse.de
Mon Nov 16 11:16:18 GMT 2020


Hi,

There's an early exit in libdebuginfod's debuginfod_query_server, which checks
both for:
- getenv (DEBUGINFOD_URLS_ENV_VAR) == NULL, and
- (getenv (DEBUGINFOD_URLS_ENV_VAR))[0] == '\0'.

In debuginfod_source_query and debuginfod_debuginfo_query (which both
end up calling debuginfod_query_server) there are also early exits checking
the same env var, but those just check for NULL.

Make the early exit tests in debuginfod-support.c match those in
libdebuginfod.

Any comments?

Thanks,
- Tom

[gdb] Improve early exits for env var in debuginfod-support.c

gdb/ChangeLog:

2020-11-16  Tom de Vries  <tdevries@suse.de>

	* debuginfod-support.c (debuginfod_source_query)
	(debuginfod_debuginfo_query): Also do early exit if
	"(getenv (DEBUGINFOD_URLS_ENV_VAR))[0] == '\0'".

---
 gdb/debuginfod-support.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index ae0f4c6c437..a7c76ab6134 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -111,7 +111,8 @@ debuginfod_source_query (const unsigned char *build_id,
 			 const char *srcpath,
 			 gdb::unique_xmalloc_ptr<char> *destname)
 {
-  if (getenv (DEBUGINFOD_URLS_ENV_VAR) == NULL)
+  const char *urls_env_var = getenv (DEBUGINFOD_URLS_ENV_VAR);
+  if (urls_env_var == NULL || urls_env_var[0] == '\0')
     return scoped_fd (-ENOSYS);
 
   debuginfod_client_up c = debuginfod_init ();
@@ -147,7 +148,8 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
 			    const char *filename,
 			    gdb::unique_xmalloc_ptr<char> *destname)
 {
-  if (getenv (DEBUGINFOD_URLS_ENV_VAR) == NULL)
+  const char *urls_env_var = getenv (DEBUGINFOD_URLS_ENV_VAR);
+  if (urls_env_var == NULL || urls_env_var[0] == '\0')
     return scoped_fd (-ENOSYS);
 
   debuginfod_client_up c = debuginfod_init ();


More information about the Gdb-patches mailing list