Merge pull request #6710 from rgerhards/fix/runtime-zero-size-alloc

runtime: cleanup zero-size alloc handling and TODO items
This commit is contained in:
Rainer Gerhards 2026-04-13 09:03:01 +02:00 committed by GitHub
commit 4bb9c1cbfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 17 additions and 4 deletions

View File

@ -56,6 +56,10 @@ int cryGetKeyFromFile(const char *const fn, char **const key, unsigned *const ke
errno = EMSGSIZE;
goto done;
}
if (sb.st_size == 0) {
errno = EINVAL;
goto done;
}
if ((*key = malloc(sb.st_size)) == NULL) goto done;
if (read(fd, *key, sb.st_size) != sb.st_size) goto done;
*keylen = sb.st_size;

View File

@ -77,6 +77,10 @@ int osslGetKeyFromFile(const char* const fn, char** const key, unsigned* const k
errno = EMSGSIZE;
goto done;
}
if (sb.st_size == 0) {
errno = EINVAL;
goto done;
}
if ((*key = malloc(sb.st_size)) == NULL) goto done;
if (read(fd, *key, sb.st_size) != sb.st_size) goto done;
*keylen = sb.st_size;

View File

@ -1051,6 +1051,11 @@ static rsRetVal ATTR_NONNULL()
ABORT_FINALIZE(RS_RET_FILE_NOT_FOUND);
}
if (sb.st_size == 0) {
LogError(0, RS_RET_JSON_PARSE_ERR, "lookup table file '%s' is empty", filename);
ABORT_FINALIZE(RS_RET_JSON_PARSE_ERR);
}
CHKmalloc(iobuf = malloc(sb.st_size));
tokener = json_tokener_new();

View File

@ -1070,9 +1070,9 @@ static rsRetVal AcceptConnReq(nsd_t *pNsd, nsd_t **ppNew, char *const connInfo)
/* Store nsd_ossl_t* reference in SSL obj
* Index allocation: 0=pTcp, 1=permitExpiredCerts, 2=imdtls instance, 3=revocationCheck
*/
SSL_set_ex_data(pNew->pNetOssl->ssl, 0, pThis->pTcp);
SSL_set_ex_data(pNew->pNetOssl->ssl, 1, &pThis->permitExpiredCerts);
SSL_set_ex_data(pNew->pNetOssl->ssl, 3, &pThis->DrvrTlsRevocationCheck);
SSL_set_ex_data(pNew->pNetOssl->ssl, 0, pNew->pTcp);
SSL_set_ex_data(pNew->pNetOssl->ssl, 1, &pNew->permitExpiredCerts);
SSL_set_ex_data(pNew->pNetOssl->ssl, 3, &pNew->DrvrTlsRevocationCheck);
/* We now do the handshake */
CHKiRet(osslHandshakeCheck(pNew));

View File

@ -737,7 +737,6 @@ static rsRetVal ATTR_NONNULL(1) processDataRcvd(tcps_sess_t *pThis,
cnf_params->pszInputName, peerName, peerIP, peerPort, c);
}
if (pThis->iOctetsRemain < 1) {
/* TODO: handle the case where the octet count is 0! */
LogError(0, NO_ERRCODE,
"imtcp %s: Framing Error in received TCP message from "
"peer: (hostname) %s, (ip) %s, (port) %s: invalid octet count %d.",

View File

@ -1008,6 +1008,7 @@ static rsRetVal ATTR_NONNULL(1)
while (state == RS_READING || state == RS_STARVATION) {
switch (state) {
case RS_READING:
/* maxReads==0 is intentional and documented: it disables starvation protection. */
while (state == RS_READING && (maxReads == 0 || read_calls < maxReads)) {
iRet = pThis->pRcvData(pSess, buf, sizeof(buf), &iRcvd, &oserr, &pioDescr->ioDirection);