readlink() doesn't terminate the string for us, so our string doesn't
match properly (it will have a little extra garbage at the end).
static void get_binary_name(char *buf, size_t len)
{
- if (readlink("/proc/self/exe", buf, len) == -1) {
+ ssize_t size = readlink("/proc/self/exe", buf, len);
+ if (size < 0) {
perror("readlink");
exit(EXIT_FAILURE);
}
+
+ /* Terminate string */
+ if ((size_t)size > len)
+ size = len;
+ buf[size] = '\0';
}
/** The SnapshotGlobalSegments function computes the memory regions