Skip to content

possible use of uninitialized memory in GetExeProgramName() #99

@lvoege

Description

@lvoege

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions