1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-01 11:26:53 +03:00

tidy-up: example, tests continued

- fix skip auth if `userauthlist` is NULL.
  Closes #836 (Reported-by: @sudipm-mukherjee on github)
- fix most silenced `checksrc` warnings.
- sync examples/tests code between each other.
  (output messages, error handling, declaration order, comments)
- stop including unnecessary headers.
- always deinitialize in case of error.
- drop some redundant variables.
- add error handling where missing.
- show more error codes.
- switch `perror()` to `fprintf()`.
- fix some `printf()`s to be `fprintf()`.
- formatting.

Closes #960
This commit is contained in:
Viktor Szakats
2023-04-14 11:05:21 +00:00
parent 0162d1649c
commit 2efdb6747a
51 changed files with 1550 additions and 1289 deletions

View File

@ -10,12 +10,12 @@
#include "testinput.h"
#define FUZZ_ASSERT(COND) \
if(!(COND)) \
{ \
fprintf(stderr, "Assertion failed: " #COND "\n%s", \
strerror(errno)); \
assert((COND)); \
}
if(!(COND)) \
{ \
fprintf(stderr, "Assertion failed: " #COND "\n%s", \
strerror(errno)); \
assert((COND)); \
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
@ -27,7 +27,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
rc = libssh2_init(0);
if(rc != 0) {
if(rc) {
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
goto EXIT_LABEL;
}
@ -38,7 +38,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
written = send(socket_fds[1], data, size, 0);
if (written != size)
if(written != size)
{
// Handle whatever error case we're in.
fprintf(stderr, "send() of %zu bytes returned %zu (%d)\n",
@ -49,7 +49,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
rc = shutdown(socket_fds[1], SHUT_WR);
if (rc != 0)
if(rc)
{
fprintf(stderr, "socket shutdown failed (%d)\n", rc);
goto EXIT_LABEL;
@ -61,7 +61,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
libssh2_session_set_blocking(session, 1);
}
else {
goto EXIT_LABEL;
goto EXIT_LABEL;
}
if(libssh2_session_handshake(session, socket_fds[0])) {
@ -73,9 +73,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
EXIT_LABEL:
if (session != NULL)
if(session)
{
if (handshake_completed)
if(handshake_completed)
{
libssh2_session_disconnect(session,
"Normal Shutdown, Thank you for playing");