Commit 71620917 authored by Marius Wachtler's avatar Marius Wachtler

Fix a memory corruption in posix.urandom

In addition fix a valgrind uninitialized memory use warning
and close the opened file descriptor in posix.urandom
parent 6eaa7283
...@@ -345,6 +345,7 @@ void registerMainThread() { ...@@ -345,6 +345,7 @@ void registerMainThread() {
current_threads[gettid()] = new ThreadStateInternal(find_stack(), pthread_self()); current_threads[gettid()] = new ThreadStateInternal(find_stack(), pthread_self());
struct sigaction act; struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
act.sa_sigaction = _thread_context_dump; act.sa_sigaction = _thread_context_dump;
struct sigaction oldact; struct sigaction oldact;
......
...@@ -39,7 +39,7 @@ Box* urandom(Box* _n) { ...@@ -39,7 +39,7 @@ Box* urandom(Box* _n) {
int fd = ::open("/dev/urandom", O_RDONLY); int fd = ::open("/dev/urandom", O_RDONLY);
RELEASE_ASSERT(fd > 0, ""); RELEASE_ASSERT(fd > 0, "");
BoxedString* r = static_cast<BoxedString*>(PyString_FromStringAndSize(NULL, sizeof(n))); BoxedString* r = static_cast<BoxedString*>(PyString_FromStringAndSize(NULL, n));
RELEASE_ASSERT(r, ""); RELEASE_ASSERT(r, "");
char* buf = PyString_AsString(r); char* buf = PyString_AsString(r);
...@@ -49,6 +49,7 @@ Box* urandom(Box* _n) { ...@@ -49,6 +49,7 @@ Box* urandom(Box* _n) {
assert(this_read > 0); assert(this_read > 0);
total_read += this_read; total_read += this_read;
} }
::close(fd);
return r; return r;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment