1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-01 11:26:52 +03:00

torture_session.c: Append a '\0' before string comparison

ssh_channel_read() reads the data into the buffer, but doesn't
append a '\0' after it. When the buffer is asserted to be equal to
a string further in the test, the assertion could fail if the byte
after the data stored in the buffer doesn't contain '\0' (and it mayn't)

This commit appends a '\0' after the data read into the buffer before
comparing it with a string.

Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Eshan Kelkar
2023-11-21 19:47:33 +05:30
committed by Sahana Prasad
parent 2df2324638
commit 19ced21adb

View File

@ -471,6 +471,8 @@ torture_channel_read_stderr(void **state)
/* Everything in stderr */
rc = ssh_channel_read(channel, buffer, sizeof(buffer), 1);
assert_int_equal(rc, strlen("ABCD"));
buffer[rc] = '\0';
assert_string_equal("ABCD", buffer);
ssh_channel_free(channel);