C crypt function, malloc and valgrind -
my man page crypt function states that:
"the return value points static data content overwritten each call."
however, when using sha512 version (ie, salt starts $6$...), valgrind not seem agree. unless free pointer crypt returns, gets upset:
120 bytes in 1 blocks still reachable in loss record 1 of 1 @ 0x4c2bba0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 0x4c2df4f: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 0x521f4d4: __sha512_crypt (sha512-crypt.c:437)
conversely, valgrind fine if use des version (so salt not start $6$ or similar).
what's going on here , behaviour explained anywhere?
thanks in advance.
edit: platform ubuntu 15.04 64-bit. here's program:
#define _xopen_source 700 #include <unistd.h> int main(int argc, char** argv) { char *hash = crypt("password", "$6$salty"); return 0; }
for crypt variations, preallocated buffer not big enough, allocates (via malloc) buffer reused next call crypt
needs large buffer (possibly after realloc
ing it). that's why noted "still reachable" valgrind -- there's static variable in library points @ block.
if free it, it's next call crypt misbehave (likely giving runtime error reusing freed block).
no matter how many times call crypt
there 1 block identified valgrind this. isn't real memory leak, constant overhead library pretty impossible avoid.
generally want ignore valgrind messages "still reachable" blocks unless amount of memory unexpectedly large, or requests coming place should not storing returned pointers in global variables.
Comments
Post a Comment