mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-15 12:50:41 +01:00
bugfixes: small issues detected by clang static analyzer 10
This commit is contained in:
parent
56b1dd06ae
commit
deb98fecc1
@ -328,15 +328,15 @@ dockerContLogsBufDestruct(docker_cont_logs_buf_t *pThis) {
|
||||
}
|
||||
|
||||
static rsRetVal
|
||||
dockerContLogsBufWrite(docker_cont_logs_buf_t *pThis, const uchar *pdata, size_t write_size) {
|
||||
dockerContLogsBufWrite(docker_cont_logs_buf_t *const pThis, const uchar *const pdata, const size_t write_size) {
|
||||
DEFiRet;
|
||||
|
||||
imdocker_buf_t *mem = pThis->buf;
|
||||
imdocker_buf_t *const mem = pThis->buf;
|
||||
if (mem->len + write_size + 1 > mem->data_size) {
|
||||
uchar *pbuf=NULL;
|
||||
if ((pbuf = realloc(mem->data, mem->len + write_size + 1)) == NULL) {
|
||||
uchar *const pbuf = realloc(mem->data, mem->len + write_size + 1);
|
||||
if(pbuf == NULL) {
|
||||
LogError(errno, RS_RET_ERR, "%s() - realloc failed!\n", __FUNCTION__);
|
||||
return RS_RET_OUT_OF_MEMORY;
|
||||
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
||||
}
|
||||
mem->data = pbuf;
|
||||
mem->data_size = mem->len+ write_size + 1;
|
||||
@ -352,7 +352,8 @@ dockerContLogsBufWrite(docker_cont_logs_buf_t *pThis, const uchar *pdata, size_t
|
||||
pThis->bytes_remaining -= write_size;
|
||||
}
|
||||
|
||||
return iRet;
|
||||
finalize_it:
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
rsRetVal imdockerReqNew(imdocker_req_t **ppThis) {
|
||||
@ -739,7 +740,8 @@ dockerContLogReqsPrint(docker_cont_log_instances_t *pThis) {
|
||||
/* NOTE: not thread safe */
|
||||
static rsRetVal
|
||||
dockerContLogReqsAdd(docker_cont_log_instances_t *pThis,
|
||||
docker_cont_logs_inst_t *pContLogsReqInst) {
|
||||
docker_cont_logs_inst_t *pContLogsReqInst)
|
||||
{
|
||||
DEFiRet;
|
||||
if (!pContLogsReqInst) {
|
||||
return RS_RET_ERR;
|
||||
@ -753,9 +755,11 @@ dockerContLogReqsAdd(docker_cont_log_instances_t *pThis,
|
||||
if (!hashtable_insert(pThis->ht_container_log_insts, keyName, pContLogsReqInst)) {
|
||||
ABORT_FINALIZE(RS_RET_ERR);
|
||||
}
|
||||
keyName = NULL;
|
||||
}
|
||||
}
|
||||
finalize_it:
|
||||
free(keyName);
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
|
||||
@ -1195,7 +1195,7 @@ cache_entry_get(wrkrInstanceData_t *pWrkrData,
|
||||
*/
|
||||
static rsRetVal
|
||||
cache_entry_add(wrkrInstanceData_t *pWrkrData,
|
||||
int isnsmd, const char *key, struct fjson_object *jso, time_t now)
|
||||
int isnsmd, const char *key, struct fjson_object *jso, time_t now, const int bDupKey)
|
||||
{
|
||||
DEFiRet;
|
||||
struct cache_entry_s *cache_entry = NULL;
|
||||
@ -1205,7 +1205,7 @@ cache_entry_add(wrkrInstanceData_t *pWrkrData,
|
||||
(void)cache_delete_expired_entries(pWrkrData, isnsmd, now);
|
||||
CHKmalloc(cache_entry = cache_entry_new(now + pWrkrData->pData->cacheEntryTTL, jso));
|
||||
if (cache_entry) {
|
||||
if (!hashtable_insert(ht, (void *)key, cache_entry))
|
||||
if (!hashtable_insert(ht, (void *)(bDupKey ? strdup(key) : key), cache_entry))
|
||||
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
||||
|
||||
if (isnsmd) {
|
||||
@ -1239,14 +1239,14 @@ static struct fjson_object *cache_entry_get_nsmd(wrkrInstanceData_t *pWrkrData,
|
||||
static rsRetVal cache_entry_add_md(wrkrInstanceData_t *pWrkrData, const char *key,
|
||||
struct fjson_object *jso, time_t now)
|
||||
{
|
||||
return cache_entry_add(pWrkrData, 0, key, jso, now);
|
||||
return cache_entry_add(pWrkrData, 0, key, jso, now, 0);
|
||||
}
|
||||
|
||||
/* must be called with cache->cacheMtx held */
|
||||
static rsRetVal cache_entry_add_nsmd(wrkrInstanceData_t *pWrkrData, const char *key,
|
||||
struct fjson_object *jso, time_t now)
|
||||
{
|
||||
return cache_entry_add(pWrkrData, 1, key, jso, now);
|
||||
return cache_entry_add(pWrkrData, 1, key, jso, now, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -1925,8 +1925,9 @@ CODESTARTdoAction
|
||||
}
|
||||
|
||||
if(jNsMeta) {
|
||||
if ((iRet = cache_entry_add_nsmd(pWrkrData, strdup(ns), jNsMeta, now)))
|
||||
if ((iRet = cache_entry_add_nsmd(pWrkrData, ns, jNsMeta, now))) {
|
||||
ABORT_FINALIZE(iRet);
|
||||
}
|
||||
}
|
||||
json_object_put(jReply);
|
||||
jReply = NULL;
|
||||
|
||||
@ -1039,7 +1039,9 @@ CODESTARTnewActInst
|
||||
if (expiration > 0) {
|
||||
char buf[40];
|
||||
snprintf(buf, 40, "%lld", expiration);
|
||||
#ifndef __clang_analyzer__
|
||||
pData->expiration = cstring_bytes(strdup(buf));
|
||||
#endif
|
||||
}
|
||||
} else if (!strcmp(actpblk.descr[i].name, "body_template")) {
|
||||
pData->body_template = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Module begun 2011-07-01 by Rainer Gerhards
|
||||
*
|
||||
* Copyright 2011-2018 Rainer Gerhards and Others.
|
||||
* Copyright 2011-2019 Rainer Gerhards and Others.
|
||||
*
|
||||
* This file is part of the rsyslog runtime library.
|
||||
*
|
||||
@ -3436,7 +3436,7 @@ initFunc_re_match(struct cnffunc *func)
|
||||
}
|
||||
} else { /* regexp object could not be loaded */
|
||||
parser_errmsg("could not load regex support - regex ignored");
|
||||
ABORT_FINALIZE(RS_RET_ERR);
|
||||
ABORT_FINALIZE(localRet);
|
||||
}
|
||||
|
||||
finalize_it:
|
||||
|
||||
@ -598,7 +598,6 @@ int TCPSessGSSRecv(tcps_sess_t *pSess, void *buf, size_t buf_len, ssize_t *piLen
|
||||
OM_uint32 maj_stat, min_stat;
|
||||
int fdSess;
|
||||
int conf_state;
|
||||
int state;
|
||||
gss_sess_t *pGSess;
|
||||
|
||||
assert(pSess->pUsr != NULL);
|
||||
@ -606,7 +605,7 @@ int TCPSessGSSRecv(tcps_sess_t *pSess, void *buf, size_t buf_len, ssize_t *piLen
|
||||
pGSess = (gss_sess_t*) pSess->pUsr;
|
||||
|
||||
netstrm.GetSock(pSess->pStrm, &fdSess); // TODO: method access, CHKiRet!
|
||||
if ((state = gssutil.recv_token(fdSess, &xmit_buf)) <= 0)
|
||||
if(gssutil.recv_token(fdSess, &xmit_buf) <= 0)
|
||||
ABORT_FINALIZE(RS_RET_GSS_ERR);
|
||||
|
||||
context = &pGSess->gss_context;
|
||||
|
||||
@ -320,7 +320,6 @@ static rsRetVal ATTR_NONNULL()
|
||||
checkInstance(instanceConf_t *const inst)
|
||||
{
|
||||
DEFiRet;
|
||||
int nBrokers;
|
||||
char kafkaErrMsg[1024];
|
||||
|
||||
/* main kafka conf */
|
||||
@ -431,7 +430,7 @@ checkInstance(instanceConf_t *const inst)
|
||||
#endif
|
||||
|
||||
DBGPRINTF("imkafka: setting brokers: '%s'\n", inst->brokers);
|
||||
if((nBrokers = rd_kafka_brokers_add(inst->rk, (char*)inst->brokers)) == 0) {
|
||||
if(rd_kafka_brokers_add(inst->rk, (char*)inst->brokers) == 0) {
|
||||
if(inst->bReportErrs) {
|
||||
LogError(0, RS_RET_KAFKA_NO_VALID_BROKERS,
|
||||
"imkafka: no valid brokers specified: %s", inst->brokers);
|
||||
|
||||
@ -350,7 +350,6 @@ static rsRetVal doTryResume(instanceData *pData)
|
||||
DEFiRet;
|
||||
struct addrinfo *res;
|
||||
struct addrinfo hints;
|
||||
unsigned e;
|
||||
|
||||
switch (pData->eDestState) {
|
||||
case eDestFORW_SUSP:
|
||||
@ -369,8 +368,7 @@ static rsRetVal doTryResume(instanceData *pData)
|
||||
hints.ai_flags = AI_NUMERICSERV;
|
||||
hints.ai_family = glbl.GetDefPFFamily();
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
if((e = getaddrinfo(pData->f_hname,
|
||||
getFwdSyslogPt(pData), &hints, &res)) == 0) {
|
||||
if(getaddrinfo(pData->f_hname, getFwdSyslogPt(pData), &hints, &res) == 0) {
|
||||
dbgprintf("%s found, resuming.\n", pData->f_hname);
|
||||
pData->f_addr = res;
|
||||
pData->eDestState = eDestFORW;
|
||||
@ -483,7 +481,6 @@ ENDdoAction
|
||||
BEGINparseSelectorAct
|
||||
uchar *q;
|
||||
int i;
|
||||
int error;
|
||||
int bErr;
|
||||
struct addrinfo hints, *res;
|
||||
TCPFRAMINGMODE tcp_framing = TCP_FRAMING_OCTET_STUFFING;
|
||||
@ -625,7 +622,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1)
|
||||
hints.ai_flags = AI_NUMERICSERV;
|
||||
hints.ai_family = glbl.GetDefPFFamily();
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
if( (error = getaddrinfo(pData->f_hname, getFwdSyslogPt(pData), &hints, &res)) != 0) {
|
||||
if(getaddrinfo(pData->f_hname, getFwdSyslogPt(pData), &hints, &res) != 0) {
|
||||
pData->eDestState = eDestFORW_UNKN;
|
||||
} else {
|
||||
pData->eDestState = eDestFORW;
|
||||
|
||||
@ -1226,7 +1226,6 @@ static rsRetVal
|
||||
openKafka(instanceData *const __restrict__ pData)
|
||||
{
|
||||
char errstr[MAX_ERRMSG];
|
||||
int nBrokers = 0;
|
||||
DEFiRet;
|
||||
|
||||
if(pData->bIsOpen)
|
||||
@ -1291,7 +1290,7 @@ openKafka(instanceData *const __restrict__ pData)
|
||||
rd_kafka_conf_set_log_cb(pData->rk, kafkaLogger);
|
||||
# endif
|
||||
DBGPRINTF("omkafka setting brokers: '%s'n", pData->brokers);
|
||||
if((nBrokers = rd_kafka_brokers_add(pData->rk, (char*)pData->brokers)) == 0) {
|
||||
if(rd_kafka_brokers_add(pData->rk, (char*)pData->brokers) == 0) {
|
||||
LogError(0, RS_RET_KAFKA_NO_VALID_BROKERS,
|
||||
"omkafka: no valid brokers specified: %s\n", pData->brokers);
|
||||
ABORT_FINALIZE(RS_RET_KAFKA_NO_VALID_BROKERS);
|
||||
|
||||
@ -290,9 +290,10 @@ static rsRetVal initConn(instanceData *pData, int bSilent)
|
||||
int is_sqlite2 = !strcmp((const char *)pData->drvrName, "sqlite");
|
||||
int is_sqlite3 = !strcmp((const char *)pData->drvrName, "sqlite3");
|
||||
if(is_sqlite2 || is_sqlite3) {
|
||||
char *dn = strdup((char*)pData->dbName);
|
||||
dn = dirname(dn);
|
||||
char *const dn_org = strdup((char*)pData->dbName);
|
||||
char *const dn = dirname(dn_org);
|
||||
dbi_conn_set_option(pData->conn, is_sqlite3 ? "sqlite3_dbdir" : "sqlite_dbdir",dn);
|
||||
free(dn_org); /* Free original buffer - dirname may return different pointer */
|
||||
|
||||
char *tmp = strdup((char*)pData->dbName);
|
||||
char *bn = basename(tmp);
|
||||
|
||||
@ -367,7 +367,7 @@ UDPSend(wrkrInstanceData_t *pWrkrData, uchar *pszSourcename, char *msg, size_t l
|
||||
int bSendSuccess;
|
||||
instanceData *pData;
|
||||
struct sockaddr_in *tempaddr,source_ip;
|
||||
libnet_ptag_t ip, ipo;
|
||||
libnet_ptag_t ip;
|
||||
libnet_ptag_t udp;
|
||||
sbool bNeedUnlock = 0;
|
||||
/* hdrOffs = fragmentation flags + offset (in bytes)
|
||||
@ -387,7 +387,7 @@ UDPSend(wrkrInstanceData_t *pWrkrData, uchar *pszSourcename, char *msg, size_t l
|
||||
len = 65528;
|
||||
}
|
||||
|
||||
ip = ipo = udp = 0;
|
||||
ip = udp = 0;
|
||||
if(pWrkrData->sourcePort++ >= pData->sourcePortEnd){
|
||||
pWrkrData->sourcePort = pData->sourcePortStart;
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ finalize_it:
|
||||
CODE_STD_FINALIZERnewParserInst
|
||||
if(lst != NULL)
|
||||
cnfparamvalsDestruct(pvals, &parserpblk);
|
||||
if(iRet != RS_RET_OK)
|
||||
if(iRet != RS_RET_OK && inst != NULL)
|
||||
freeParserInst(inst);
|
||||
ENDnewParserInst
|
||||
|
||||
|
||||
@ -1298,6 +1298,7 @@ finalize_it:
|
||||
free(pPathBuf);
|
||||
if(iRet != RS_RET_OK)
|
||||
abortCnfUse(&pNew);
|
||||
free(pNew); /* is NULL again if properly consumed, else clean up */
|
||||
pthread_mutex_unlock(&mutObjGlobalOp);
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
@ -1872,8 +1872,8 @@ DequeueConsumableElements(qqueue_t *const pThis, wti_t *const pWti,
|
||||
}
|
||||
}
|
||||
if(keep_running) {
|
||||
keep_running = ((iQueueSize = getLogicalQueueSize(pThis)) > 0
|
||||
&& nDequeued < pThis->iDeqBatchSize);
|
||||
keep_running = (getLogicalQueueSize(pThis) > 0)
|
||||
&& (nDequeued < pThis->iDeqBatchSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* This is a tool for processing rsyslog encrypted log files.
|
||||
*
|
||||
* Copyright 2013-2016 Adiscon GmbH
|
||||
* Copyright 2013-2019 Adiscon GmbH
|
||||
*
|
||||
* This file is part of rsyslog.
|
||||
*
|
||||
@ -195,6 +195,7 @@ initCrypt(FILE *eifp)
|
||||
if((r = eiGetIV(eifp, iv, blkLength)) != 0) goto done;
|
||||
|
||||
size_t keyLength = gcry_cipher_get_algo_keylen(cry_algo);
|
||||
assert(cry_key != NULL); /* "fix" clang 10 static analyzer false positive */
|
||||
if(strlen(cry_key) != keyLength) {
|
||||
fprintf(stderr, "invalid key length; key is %u characters, but "
|
||||
"exactly %llu characters are required\n", cry_keylen,
|
||||
@ -526,6 +527,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
setKey();
|
||||
assert(cry_key != NULL);
|
||||
|
||||
if(mode == MD_WRITE_KEYFILE) {
|
||||
if(optind != argc) {
|
||||
@ -543,6 +545,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
assert(cry_key != NULL);
|
||||
memset(cry_key, 0, cry_keylen); /* zero-out key store */
|
||||
cry_keylen = 0;
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user