postgresql-interfaces/psqlodbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
[postgresql-interfaces/psqlodbc] issue #99: possible use of uninitialized memory in GetExeProgramName()
2+ messages / 2 participants
[nested] [flat]

* [postgresql-interfaces/psqlodbc] issue #99: possible use of uninitialized memory in GetExeProgramName()
@ 2025-03-26 00:08  "lvoege (@lvoege)" <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: lvoege (@lvoege) @ 2025-03-26 00:08 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

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;


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #99: possible use of uninitialized memory in GetExeProgramName()
@ 2025-03-27 09:38  "davecramer (@davecramer)" <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: davecramer (@davecramer) @ 2025-03-27 09:38 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

closed with https://github.com/postgresql-interfaces/psqlodbc/pull/100

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-03-27 09:38 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-03-26 00:08 [postgresql-interfaces/psqlodbc] issue #99: possible use of uninitialized memory in GetExeProgramName() "lvoege (@lvoege)" <[email protected]>
2025-03-27 09:38 Re: [postgresql-interfaces/psqlodbc] issue #99: possible use of uninitialized memory in GetExeProgramName() "davecramer (@davecramer)" <[email protected]>

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