@mikael The from_buffer method doesn't do what you think it's doing. ctypes.c_void_p.from_buffer(buffer) assumes that buffer contains data for a c_void_p, and gives you a c_void_p backed by that data. Basically, it's not giving you a pointer to buffer, it's interpreting the start of buffer as a pointer. Since buffer starts out as all zeroes, buf_p is a null pointer, so writing to it will crash.
I'm not quite sure, but you might be able to just pass buffer directly into the method. ctypes might convert it to a pointer automatically - it does that for (read-only) bytes objects, I'm not sure if it works with bytearrays as well.
If not, you can use ctypes.create_string_buffer to create a new c_char array of the given length. This array can definitely be passed into C functions/methods. To get the data out of the array (after you've read into it), you can use the raw attribute (to get the entire data) or the value attribute (to get everything up to the first zero byte - this is useful for C strings).