Skip to content

Commit 7bcb223

Browse files
willco007Will Cosgrove
andauthored
comp.c: Add defensive code if src buffer is empty/null (libssh2#1813)
If `src` is NULL a 25 byte buffer is still allocated and returned but with a length of zero and no error. This causes error handling to be a bit tricky on the other side of this call so we should clean up on this side and return an error. Reviewed: Michael Buckley Co-authored-by: Will Cosgrove <will@everydaysoftware.net>
1 parent 704299e commit 7bcb223

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/comp.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session,
281281
}
282282
else if(status == Z_BUF_ERROR) {
283283
/* the input data has been exhausted so we are done */
284+
285+
if((out_maxlen - strm->avail_out) == 0) {
286+
/* nothing was decompressed */
287+
LIBSSH2_FREE(session, out);
288+
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
289+
"zlib empty src error %d", status));
290+
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
291+
"decompression failure");
292+
}
293+
284294
break;
285295
}
286296
else {

0 commit comments

Comments
 (0)