Crystal::System::User#from_*?
et al. don't work if required buffer size greater than initial buffer size
#14619
Labels
Bug Report
While looking at #14614, I noticed that all methods using
System.retry_with_buffer
do not work if the required buffer size to store strings in is greater than the initial buffer size provided.Here's an example (
Group#from_name?
):LibC.getgrnam_r
(and the other relevant methods) set the value of the last argument to NULL if an error occured:However, the last argument provided is
pointerof(grp_pointer)
, sogrp_pointer
will be set tonull
if the buffer was to small - but this variable is never reset and also used as the second argument togetgrnam_r
(where the group data should be stored in).A quick fix would be to replace the second argument (
grp_pointer
) withpointerof(grp)
, so the pointer is nevernull
.With this fix, there's also no reason to define the value of
grp_pointer
, it could just be replaced by aout grp_pointer
inside the function call.TL;DR: After one iteration of
retry_with_buffer
,grp_pointer = null
, which causes a segfault in very special circumstances.With this bash script, you can get your very own segfault:
The text was updated successfully, but these errors were encountered: