1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-20 02:42:09 +03:00

misc/libssh2_copy_string: avoid malloc zero bytes

Avoids the inconsistent malloc return code for malloc(0)

Closes #686
This commit is contained in:
Daniel Stenberg
2022-03-21 09:31:39 +01:00
parent 049003c3d6
commit e7e1312b0c

View File

@@ -817,12 +817,18 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
return -1; return -1;
} }
*outbuf = LIBSSH2_ALLOC(session, str_len); if(str_len) {
if(*outbuf) { *outbuf = LIBSSH2_ALLOC(session, str_len);
memcpy(*outbuf, str, str_len); if(*outbuf) {
memcpy(*outbuf, str, str_len);
}
else {
return -1;
}
} }
else { else {
return -1; *outlen = 0;
*outbuf = NULL;
} }
if(outlen) if(outlen)