1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-28 10:29:03 +00:00

Update libssh2 to 1.11.1

This commit is contained in:
dmiller
2025-04-14 17:20:50 +00:00
parent 58ef6f6dac
commit 2bc341de52
118 changed files with 11071 additions and 4234 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Patrick Monnerat, D+H <patrick.monnerat@dh.com>
* Copyright (C) Patrick Monnerat <patrick@monnerat.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@@ -34,6 +34,8 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/* Character encoding wrappers. */
@@ -46,6 +48,7 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@@ -56,6 +59,11 @@
#define OFFSET_OF(t, f) ((size_t) ((char *) &((t *) 0)->f - (char *) 0))
#define ALLOC(s, sz) ((s)? LIBSSH2_ALLOC((s), (sz)): malloc(sz))
#define REALLOC(s, p, sz) ((s)? LIBSSH2_REALLOC((s), (p), (sz)): \
realloc((p), (sz)))
#define FREE(s, p) ((s)? LIBSSH2_FREE((s), (p)): free(p))
struct _libssh2_string_cache {
libssh2_string_cache * next;
@@ -80,7 +88,7 @@ terminator_size(unsigned short ccsid)
/* Return the null-terminator size for the given CCSID. */
/* Fast check usual CCSIDs. */
switch (ccsid) {
switch(ccsid) {
case CCSID_UTF8:
case 0: /* Job CCSID is SBCS EBCDIC. */
return 1;
@@ -90,19 +98,19 @@ terminator_size(unsigned short ccsid)
/* Convert an UTF-8 NUL to the target CCSID: use the converted size as
result. */
memset((void *) &outcode, 0, sizeof outcode);
memset((void *) &outcode, 0, sizeof(outcode));
outcode.CCSID = ccsid;
cd = QtqIconvOpen(&outcode, (QtqCode_T *) &utf8code);
if (cd.return_value == -1)
if(cd.return_value == -1)
return -1;
inp = "";
ilen = 1;
outp = buf;
olen = sizeof buf;
olen = sizeof(buf);
iconv(cd, &inp, &ilen, &outp, &olen);
iconv_close(cd);
olen = sizeof buf - olen;
return olen? olen: -1;
olen = sizeof(buf - olen);
return olen ? olen : -1;
}
static char *
@@ -124,66 +132,66 @@ convert_ccsid(LIBSSH2_SESSION *session, libssh2_string_cache **cache,
QtqCode_T outcode;
iconv_t cd;
if (!instring) {
if (outlen)
if(!instring) {
if(outlen)
*outlen = 0;
return NULL;
}
if (outlen)
if(outlen)
*outlen = -1;
if (!session || !cache)
if(!cache)
return NULL;
/* Get terminator size. */
termsize = terminator_size(outccsid);
if (termsize < 0)
if(termsize < 0)
return NULL;
/* Prepare conversion parameters. */
memset((void *) &incode, 0, sizeof incode);
memset((void *) &outcode, 0, sizeof outcode);
memset((void *) &incode, 0, sizeof(incode));
memset((void *) &outcode, 0, sizeof(outcode));
incode.CCSID = inccsid;
outcode.CCSID = outccsid;
curlen = OFFSET_OF(libssh2_string_cache, string);
inp = (char *) instring;
ilen = inlen;
buflen = inlen + curlen;
if (inlen < 0) {
if(inlen < 0) {
incode.length_option = 1;
buflen = STRING_GRANULE;
ilen = 0;
}
/* Allocate output string buffer and open conversion descriptor. */
dst = LIBSSH2_ALLOC(session, buflen + termsize);
if (!dst)
dst = ALLOC(session, buflen + termsize);
if(!dst)
return NULL;
cd = QtqIconvOpen(&outcode, &incode);
if (cd.return_value == -1) {
LIBSSH2_FREE(session, (char *) dst);
if(cd.return_value == -1) {
FREE(session, dst);
return NULL;
}
/* Convert string. */
for (;;) {
for(;;) {
outp = dst + curlen;
olen = buflen - curlen;
i = iconv(cd, &inp, &ilen, &outp, &olen);
if (inlen < 0 && olen == buflen - curlen) {
if(inlen < 0 && olen == buflen - curlen) {
/* Special case: converted 0-length (sub)strings do not store the
terminator. */
if (termsize) {
if(termsize) {
memset(outp, 0, termsize);
olen -= termsize;
}
}
curlen = buflen - olen;
if (i >= 0 || errno != E2BIG)
if(i >= 0 || errno != E2BIG)
break;
/* Must expand buffer. */
buflen += STRING_GRANULE;
outp = LIBSSH2_REALLOC(session, dst, buflen + termsize);
if (!outp)
outp = REALLOC(session, dst, buflen + termsize);
if(!outp)
break;
dst = outp;
}
@@ -191,20 +199,20 @@ convert_ccsid(LIBSSH2_SESSION *session, libssh2_string_cache **cache,
iconv_close(cd);
/* Check for error. */
if (i < 0 || !outp) {
LIBSSH2_FREE(session, dst);
if(i < 0 || !outp) {
FREE(session, dst);
return NULL;
}
/* Process terminator. */
if (inlen < 0)
if(inlen < 0)
curlen -= termsize;
else if (termsize)
else if(termsize)
memset(dst + curlen, 0, termsize);
/* Shorten buffer if possible. */
if (curlen < buflen)
dst = LIBSSH2_REALLOC(session, dst, curlen + termsize);
if(curlen < buflen)
dst = REALLOC(session, dst, curlen + termsize);
/* Link to cache. */
outstring = (libssh2_string_cache *) dst;
@@ -212,7 +220,7 @@ convert_ccsid(LIBSSH2_SESSION *session, libssh2_string_cache **cache,
*cache = outstring;
/* Return length if required. */
if (outlen)
if(outlen)
*outlen = curlen - OFFSET_OF(libssh2_string_cache, string);
return outstring->string;
@@ -242,10 +250,10 @@ libssh2_release_string_cache(LIBSSH2_SESSION *session,
{
libssh2_string_cache *p;
if (session && cache)
while ((p = *cache)) {
if(cache)
while((p = *cache)) {
*cache = p->next;
LIBSSH2_FREE(session, (char *) p);
FREE(session, (char *) p);
}
}