From: https://github.com/libssh2/libssh2/commit/e7e1312b0cbfa643e2f8bf5f2036ce5147ed797d From: bagder Date: 21 Mar 2022 10:11 -0800 Subject: misc/libssh2_copy_string: avoid malloc zero bytes #686 Notes: * Avoid the inconsistent malloc return code for malloc(0) --- libssh2-1.10.0/src/misc.c 2019-09-13 14:39:11.000000000 +0800 +++ libssh2-1.10.0/src/misc.c 2022-09-29 18:27:13.604424483 +0800 @@ -794,12 +794,18 @@ return -1; } - *outbuf = LIBSSH2_ALLOC(session, str_len); - if(*outbuf) { - memcpy(*outbuf, str, str_len); + if(str_len) { + *outbuf = LIBSSH2_ALLOC(session, str_len); + if(*outbuf) { + memcpy(*outbuf, str, str_len); + } + else { + return -1; + } } else { - return -1; + *outlen = 0; + *outbuf = NULL; } if(outlen)