if (filename == NULL)
filename = DEFAULT_LOG_FILENAME;
file_ctx->prefix = SCStrdup(filename);
+ if (unlikely(file_ctx->prefix == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate file prefix");
+ exit(EXIT_FAILURE);
+ }
const char *s_limit = NULL;
file_ctx->size_limit = DEFAULT_LIMIT;
if (file_ctx->filename != NULL)
filename = file_ctx->filename;
else {
- filename = file_ctx->filename = SCMalloc(PATH_MAX); /* XXX some sane default? */
- if (filename == NULL)
+ filename = SCMalloc(PATH_MAX); /* XXX some sane default? */
+ if (unlikely(filename == NULL))
return -1;
+ file_ctx->filename = filename;
memset(filename, 0x00, PATH_MAX);
}
SCLogDebug("LIBHTP server %s", s->name);
HTPCfgRec *nextrec = cfglist.next;
- HTPCfgRec *htprec = cfglist.next = SCMalloc(sizeof(HTPCfgRec));
+ HTPCfgRec *htprec = SCMalloc(sizeof(HTPCfgRec));
if (NULL == htprec)
exit(EXIT_FAILURE);
memset(htprec, 0x00, sizeof(*htprec));
+ cfglist.next = htprec;
+
cfglist.next->next = nextrec;
cfglist.next->cfg = htp_config_create();
if (NULL == cfglist.next->cfg) {
ssl_state->curr_connp->trec_len = ssl_state->curr_connp->trec_len + 2 * input_len + 1;
ssl_state->curr_connp->trec = SCRealloc( ssl_state->curr_connp->trec, ssl_state->curr_connp->trec_len );
}
- if (ssl_state->curr_connp->trec == NULL) {
+ if (unlikely(ssl_state->curr_connp->trec == NULL)) {
ssl_state->curr_connp->trec_len = 0;
/* error, skip packet */
parsed += input_len;
return -1;
snprintf(seq_node->name, DEFAULT_NAME_LEN, "%d", seq_idx++);
seq_node->val = SCStrdup(value);
+ if (unlikely(seq_node->val == NULL)) {
+ SCFree(seq_node->name);
+ return -1;
+ }
TAILQ_INSERT_TAIL(&parent->head, seq_node, next);
}
else {
goto end;
}
node->name = SCStrdup(key);
+ if (unlikely(node->name == NULL)) {
+ ConfNodeFree(node);
+ SCLogWarning(SC_ERR_MEM_ALLOC,
+ "Failed to allocate memory for configuration.");
+ goto end;
+ }
node->parent = parent;
node->final = final;
TAILQ_INSERT_TAIL(&parent->head, node, next);
if (node->val != NULL)
SCFree(node->val);
node->val = SCStrdup(val);
+ if (unlikely(node->val == NULL)) {
+ return 0;
+ }
return 1;
}
if (node->val != NULL)
SCFree(node->val);
node->val = SCStrdup(val);
+ if (unlikely(node->val == NULL)) {
+ return 0;
+ }
node->final = 1;
return 1;
}
level++;
TAILQ_FOREACH(child, &node->head, next) {
name[level] = SCStrdup(child->name);
+ if (unlikely(name[level] == NULL)) {
+ continue;
+ }
if (prefix == NULL) {
printf("%s = %s\n", ConfPrintNameArray(name, level),
child->val);
}
temp->head[0] = pctx;
temp->tm_name = SCStrdup(tm_name);
+ if (unlikely(temp->tm_name == NULL)) {
+ SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock);
+ return 0;
+ }
if (prev == NULL)
sc_perf_op_ctx->pctmi = temp;
fd->flags = contentflags;
fd->name = SCStrdup(varname);
+ if (unlikely(fd->name == NULL))
+ goto error;
fd->idx = VariableNameGetIdx(de_ctx, varname, DETECT_FLOWVAR);
/* Okay so far so good, lets get this into a SigMatch
int ret = 0, res = 0;
int ov[MAX_SUBSTRINGS];
const char *str_ptr;
- char *orig;
+ char *orig = NULL;
char *tmp_str;
uint32_t flag = 0;
}
tls->subject = SCStrdup(tmp_str);
+ if (unlikely(tls->subject == NULL)) {
+ goto error;
+ }
SCFree(orig);
return tls;
error:
+ if (orig != NULL)
+ SCFree(orig);
if (tls != NULL)
DetectTlsSubjectFree(tls);
return NULL;
int ret = 0, res = 0;
int ov[MAX_SUBSTRINGS];
const char *str_ptr;
- char *orig;
+ char *orig = NULL;
char *tmp_str;
uint32_t flag = 0;
}
tls->issuerdn = SCStrdup(tmp_str);
+ if (unlikely(tls->issuerdn == NULL)) {
+ goto error;
+ }
SCFree(orig);
return tls;
error:
+ if (orig != NULL)
+ SCFree(orig);
if (tls != NULL)
DetectTlsIssuerDNFree(tls);
return NULL;
if (pl->filename != NULL)
filename = pl->filename;
else {
- filename = pl->filename = SCMalloc(PATH_MAX);
- if (filename == NULL) {
+ filename = SCMalloc(PATH_MAX);
+ if (unlikely(filename == NULL)) {
return -1;
}
+ pl->filename = filename;
}
/** get the time so we can have a filename with seconds since epoch */
OutputCtx *(*InitFunc)(ConfNode *))
{
OutputModule *module = SCCalloc(1, sizeof(*module));
- if (unlikely(module == NULL)) {
- SCLogError(SC_ERR_FATAL, "Fatal error encountered in OutputRegisterModule. Exiting...");
- exit(EXIT_FAILURE);
- }
+ if (unlikely(module == NULL))
+ goto error;
module->name = SCStrdup(name);
+ if (unlikely(module->name == NULL))
+ goto error;
module->conf_name = SCStrdup(conf_name);
+ if (unlikely(module->conf_name == NULL))
+ goto error;
module->InitFunc = InitFunc;
TAILQ_INSERT_TAIL(&output_modules, module, entries);
SCLogDebug("Output module \"%s\" registered.", name);
+
+ return;
+
+error:
+ SCLogError(SC_ERR_FATAL, "Fatal error encountered in OutputRegisterModule. Exiting...");
+ exit(EXIT_FAILURE);
}
/**
if (ConfGet("bpf-filter", &bpf_filter) == 1) {
if (strlen(bpf_filter) > 0) {
pfconf->bpf_filter = SCStrdup(bpf_filter);
- SCLogDebug("Going to use command-line provided bpf filter %s",
- pfconf->bpf_filter);
+ if (unlikely(pfconf->bpf_filter == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC,
+ "Can't allocate BPF filter string");
+ } else {
+ SCLogDebug("Going to use command-line provided bpf filter %s",
+ pfconf->bpf_filter);
+ }
}
} else {
if (ConfGetChildValueWithDefault(if_root, if_default, "bpf-filter", &bpf_filter) == 1) {
if (strlen(bpf_filter) > 0) {
pfconf->bpf_filter = SCStrdup(bpf_filter);
- SCLogDebug("Going to use bpf filter %s", pfconf->bpf_filter);
+ if (unlikely(pfconf->bpf_filter == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC,
+ "Can't allocate BPF filter string");
+ } else {
+ SCLogDebug("Going to use bpf filter %s",
+ pfconf->bpf_filter);
+ }
}
}
}
}
}
this->currentfile = SCStrdup(cfile->filename);
+ if (unlikely(this->currentfile == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Failed file name allocation");
+ return TM_ECODE_FAILED;
+ }
PcapFilesFree(cfile);
SCPerfInitCounterApi();
DefragInit();
mode->runmode = runmode;
mode->name = SCStrdup(name);
+ if (unlikely(mode->name == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate string");
+ exit(EXIT_FAILURE);
+ }
mode->description = SCStrdup(description);
+ if (unlikely(mode->description == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate string");
+ exit(EXIT_FAILURE);
+ }
mode->RunModeFunc = RunModeFunc;
return;
}
nd->dev = SCStrdup(dev);
+ if (unlikely(nd->dev == NULL)) {
+ SCFree(nd);
+ return -1;
+ }
TAILQ_INSERT_TAIL(&mpipe_devices, nd, next);
SCLogDebug("Mpipe device \"%s\" registered.", dev);
ptv->threads = 1;
ptv->interface = SCStrdup(pfconf->iface);
+ if (unlikely(ptv->interface == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate device string");
+ SCReturnInt(TM_ECODE_FAILED);
+ }
ptv->livedev = LiveGetDevice(pfconf->iface);
if (ptv->livedev == NULL) {
#ifdef HAVE_PFRING_SET_BPF_FILTER
if (pfconf->bpf_filter) {
ptv->bpf_filter = SCStrdup(pfconf->bpf_filter);
+ if (unlikely(ptv->bpf_filter == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Set PF_RING bpf filter failed.");
+ } else {
+ SCMutexLock(&pfring_bpf_set_filter_lock);
+ rc = pfring_set_bpf_filter(ptv->pd, ptv->bpf_filter);
+ SCMutexUnlock(&pfring_bpf_set_filter_lock);
- SCMutexLock(&pfring_bpf_set_filter_lock);
- rc = pfring_set_bpf_filter(ptv->pd, ptv->bpf_filter);
- SCMutexUnlock(&pfring_bpf_set_filter_lock);
-
- if (rc < 0) {
- SCLogInfo("Set PF_RING bpf filter \"%s\" failed.", ptv->bpf_filter);
+ if (rc < 0) {
+ SCLogInfo("Set PF_RING bpf filter \"%s\" failed.",
+ ptv->bpf_filter);
+ }
}
}
#endif /* HAVE_PFRING_SET_BPF_FILTER */
if (filter != NULL && strcmp(filter, "") != 0) {
sc_lc->op_filter = SCStrdup(filter);
+ if (sc_lc->op_filter == NULL) {
+ printf("pcre filter alloc failed\n");
+ return;
+ }
sc_lc->op_filter_regex = pcre_compile(filter, opts, &ep, &eo, NULL);
if (sc_lc->op_filter_regex == NULL) {
+ SCFree(sc_lc->op_filter);
printf("pcre compile of \"%s\" failed at offset %d : %s\n", filter,
eo, ep);
return;
}
pd->dev = SCStrdup(dev);
+ if (unlikely(pd->dev == NULL)) {
+ SCFree(pd);
+ return -1;
+ }
SC_ATOMIC_INIT(pd->pkts);
SC_ATOMIC_INIT(pd->drop);
SC_ATOMIC_INIT(pd->invalid_checksums);
} else {
known_proto[proto] = SCStrdup(name);
}
+ if (unlikely(known_proto[proto] == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Failed proto name allocation");
+ continue;
+ }
int proto_len = strlen(known_proto[proto]);
if (proto_len > 0 && known_proto[proto][proto_len - 1] == '\n')
known_proto[proto][proto_len - 1] = '\0';