mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-10-28 16:57:24 +03:00
This updates input handling to use fgets instead of scanf for safer, fixed-size buffer reading. It also introduces fflush to ensure the prompt is always visible when running through pipes (which are block-buffered instead of line-buffered). To preserve the old scanf behavior of ignoring leading spaces (the "space bug"), a helper function (confirm_overwrite) was added to skip whitespace before checking the user's response. Other checks added: - character casting: We cast characters to (unsigned char) when passing them to C library functions like isspace and tolower. In C, special characters can sometimes be read as negative numbers, which causes these library functions to crash. Casting ensures they are always safe, positive numbers. - Null checking: The processing loop and lowercase conversion were moved inside an if (fgets_ret != NULL) block so that we only try to read the buffer if fgets actually succeeds without failing. Signed-off-by: shourya <shouryarajgoyal@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/847>