I have a function that converts uids to usernames,
char *uid2name (uid_t uid)
{
struct passwd *pwd = getpwuid (uid);
if (pwd)
return strdup (pwd->pw_name);
return NULL;
}
And I call it with:
name = uid2name (atoi (blabal));
Sometimes it crashes with either ABRT
or BUS
error:
(I know there's a conversion between signed integer and unsigned ones, but I tested getpwuid function with negative values, it doesn't crash.)
Program received signal SIGBUS, Bus error.
[Switching to Thread 1088039264 (LWP 7572)]
0x00007f504afaff10 in malloc_consolidate () from /lib64/tls/libc.so.6
#0 0x00007f504afaff10 in malloc_consolidate () from /lib64/tls/libc.so.6
#1 0x00007f504afb0f17 in _int_malloc () from /lib64/tls/libc.so.6
#2 0x00007f504afb2c52 in malloc () from /lib64/tls/libc.so.6
#3 0x00007f504afa26ba in __fopen_internal () from /lib64/tls/libc.so.6
#4 0x00007f50499ce04a in internal_setent () from /lib64/libnss_files.so.2
#5 0x00007f50499ce5b0 in _nss_files_getpwuid_r ()
from /lib64/libnss_files.so.2
#6 0x00007f504afd63fd in getpwuid_r@@GLIBC_2.2.5 () from /lib64/tls/libc.so.6
#7 0x00007f504afd5d5d in getpwuid () from /lib64/tls/libc.so.6
#8 0x00007f504b783579 in uid2name (uid=Variable "uid" is not available.
) at XX.c
Any ideas what could go wrong here?