postgresql-interfaces/psqlodbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: lvoege (@lvoege) <[email protected]>
To: postgresql-interfaces/psqlodbc <[email protected]>
Subject: [postgresql-interfaces/psqlodbc] issue #99: possible use of uninitialized memory in GetExeProgramName()
Date: Wed, 26 Mar 2025 00:08:35 +0000
Message-ID: <[email protected]> (raw)

while pointing valgrind at something unrelated it spotted the use of uninitialized memory in `po_basename()` in `mylog.c`. this is because `GetExeProgramName()` calls `readlink()`, `readlink()` doesn't add a terminating null and `GetExeProgramName()` doesn't add one itself, so the `strrchr()` in `po_basename()` can then start from garbage.

this fixes it:

~~~
diff --git a/mylog.c b/mylog.c
index 9377ad2..66e24a9 100644
--- a/mylog.c
+++ b/mylog.c
@@ -133,8 +133,10 @@ const char *GetExeProgramName()
 
                for (i = 0; i < sizeof(flist) / sizeof(flist[0]); i++)
                {
-                       if (readlink(flist[i], path_name, sizeof(path_name)) > 0)
+                       ssize_t len = readlink(flist[i], path_name, sizeof(path_name));
+                       if (len > 0)
                        {
+                               path_name[len] = 0;
                                /* fprintf(stderr, "i=%d pathname=%s\n", i, path_name); */
                                STRCPY_FIXED(exename, po_basename(path_name));
                                break;


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://postgresql-interfaces/psqlodbc
  Cc: [email protected], [email protected]
  Subject: Re: [postgresql-interfaces/psqlodbc] issue #99: possible use of uninitialized memory in GetExeProgramName()
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox