[mono-threads-posix] Fix a buffer overflow (rather an information leak / over-read)
While testing Clang's AddressSanitizer, I found and fixed a buffer overflow.
Up for discussion: it might be worth importing `strlcpy` (http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/strlcpy.c?rev=1.11) for similar purposes as it provides additional safety and also helps with the readability?
- memcpy (n, name, sizeof (n) - 1);
+ strncpy (n, name, sizeof (n) - 1);
n [sizeof (n) - 1] = '\0';
pthread_setname_np (n);
}
n [sizeof (n) - 1] = '\0';
pthread_setname_np (n);
}
} else {
char n [PTHREAD_MAX_NAMELEN_NP];
} else {
char n [PTHREAD_MAX_NAMELEN_NP];
- memcpy (n, name, sizeof (n) - 1);
+ strncpy (n, name, sizeof (n) - 1);
n [sizeof (n) - 1] = '\0';
pthread_setname_np (tid, "%s", (void*)n);
}
n [sizeof (n) - 1] = '\0';
pthread_setname_np (tid, "%s", (void*)n);
}
- memcpy (n, name, sizeof (n) - 1);
+ strncpy (n, name, sizeof (n) - 1);
n [sizeof (n) - 1] = '\0';
pthread_setname_np (tid, n);
}
n [sizeof (n) - 1] = '\0';
pthread_setname_np (tid, n);
}