fix: memory leaks, resource leaks, out of bounds and bugs
ASTERISK-26119 #close Change-Id: Iecbf7d0f360a021147344c4e83ab242fd1e7512c
This commit is contained in:
parent
947f76a971
commit
820ed3d4b3
|
@ -3671,11 +3671,18 @@ op_tildetilde (struct val *a, struct val *b)
|
||||||
strip_quotes(b);
|
strip_quotes(b);
|
||||||
|
|
||||||
vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
|
vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
|
||||||
|
if (vs == NULL) {
|
||||||
|
ast_log(LOG_WARNING, "malloc() failed\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(vs,a->u.s);
|
strcpy(vs,a->u.s);
|
||||||
strcat(vs,b->u.s);
|
strcat(vs,b->u.s);
|
||||||
|
|
||||||
v = make_str(vs);
|
v = make_str(vs);
|
||||||
|
|
||||||
|
free(vs);
|
||||||
|
|
||||||
/* free arguments */
|
/* free arguments */
|
||||||
free_value(a);
|
free_value(a);
|
||||||
free_value(b);
|
free_value(b);
|
||||||
|
|
|
@ -1664,11 +1664,18 @@ op_tildetilde (struct val *a, struct val *b)
|
||||||
strip_quotes(b);
|
strip_quotes(b);
|
||||||
|
|
||||||
vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
|
vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
|
||||||
|
if (vs == NULL) {
|
||||||
|
ast_log(LOG_WARNING, "malloc() failed\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(vs,a->u.s);
|
strcpy(vs,a->u.s);
|
||||||
strcat(vs,b->u.s);
|
strcat(vs,b->u.s);
|
||||||
|
|
||||||
v = make_str(vs);
|
v = make_str(vs);
|
||||||
|
|
||||||
|
free(vs);
|
||||||
|
|
||||||
/* free arguments */
|
/* free arguments */
|
||||||
free_value(a);
|
free_value(a);
|
||||||
free_value(b);
|
free_value(b);
|
||||||
|
|
|
@ -8521,9 +8521,9 @@ int ast_say_date_with_format_ja(struct ast_channel *chan, time_t time, const cha
|
||||||
/* NOTE: if you add more options here, please try to be consistent with strftime(3) */
|
/* NOTE: if you add more options here, please try to be consistent with strftime(3) */
|
||||||
case '\'':
|
case '\'':
|
||||||
/* Literal name of a sound file */
|
/* Literal name of a sound file */
|
||||||
sndoffset=0;
|
for (sndoffset = 0 ; (format[++offset] != '\'') && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
|
||||||
for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
|
|
||||||
sndfile[sndoffset] = format[offset];
|
sndfile[sndoffset] = format[offset];
|
||||||
|
}
|
||||||
sndfile[sndoffset] = '\0';
|
sndfile[sndoffset] = '\0';
|
||||||
res = wait_file(chan,ints,sndfile,lang);
|
res = wait_file(chan,ints,sndfile,lang);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -3356,9 +3356,9 @@ static int gen_prios(struct ael_extension *exten, char *label, pval *statement,
|
||||||
#ifdef OLD_RAND_ACTION
|
#ifdef OLD_RAND_ACTION
|
||||||
struct ael_priority *rand_test, *rand_end, *rand_skip;
|
struct ael_priority *rand_test, *rand_end, *rand_skip;
|
||||||
#endif
|
#endif
|
||||||
char *buf1;
|
RAII_VAR(char *, buf1, NULL, free);
|
||||||
char *buf2;
|
RAII_VAR(char *, buf2, NULL, free);
|
||||||
char *new_label;
|
RAII_VAR(char *, new_label, NULL, free);
|
||||||
char *strp, *strp2;
|
char *strp, *strp2;
|
||||||
int default_exists;
|
int default_exists;
|
||||||
int local_control_statement_count;
|
int local_control_statement_count;
|
||||||
|
@ -4192,9 +4192,6 @@ static int gen_prios(struct ael_extension *exten, char *label, pval *statement,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buf1);
|
|
||||||
free(buf2);
|
|
||||||
free(new_label);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5053,7 +5050,10 @@ int pvalCheckType( pval *p, char *funcname, pvaltype type )
|
||||||
pval *pvalCreateNode( pvaltype type )
|
pval *pvalCreateNode( pvaltype type )
|
||||||
{
|
{
|
||||||
pval *p = calloc(1,sizeof(pval)); /* why, oh why, don't I use ast_calloc? Way, way, way too messy if I do! */
|
pval *p = calloc(1,sizeof(pval)); /* why, oh why, don't I use ast_calloc? Way, way, way too messy if I do! */
|
||||||
p->type = type; /* remember, this can be used externally or internally to asterisk */
|
/* remember, this can be used externally or internally to asterisk */
|
||||||
|
if (p) {
|
||||||
|
p->type = type;
|
||||||
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5414,14 +5414,30 @@ void pvalIncludesAddInclude( pval *p, const char *include )
|
||||||
|
|
||||||
void pvalIncludesAddIncludeWithTimeConstraints( pval *p, const char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range )
|
void pvalIncludesAddIncludeWithTimeConstraints( pval *p, const char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range )
|
||||||
{
|
{
|
||||||
pval *hr = pvalCreateNode(PV_WORD);
|
pval *hr;
|
||||||
pval *dom = pvalCreateNode(PV_WORD);
|
pval *dom;
|
||||||
pval *dow = pvalCreateNode(PV_WORD);
|
pval *dow;
|
||||||
pval *mon = pvalCreateNode(PV_WORD);
|
pval *mon;
|
||||||
pval *s = pvalCreateNode(PV_WORD);
|
pval *s;
|
||||||
|
|
||||||
if (!pvalCheckType(p, "pvalIncludeAddIncludeWithTimeConstraints", PV_INCLUDES))
|
if (!pvalCheckType(p, "pvalIncludeAddIncludeWithTimeConstraints", PV_INCLUDES)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = pvalCreateNode(PV_WORD);
|
||||||
|
dom = pvalCreateNode(PV_WORD);
|
||||||
|
dow = pvalCreateNode(PV_WORD);
|
||||||
|
mon = pvalCreateNode(PV_WORD);
|
||||||
|
s = pvalCreateNode(PV_WORD);
|
||||||
|
|
||||||
|
if (!hr || !dom || !dow || !mon || !s) {
|
||||||
|
destroy_pval(hr);
|
||||||
|
destroy_pval(dom);
|
||||||
|
destroy_pval(dow);
|
||||||
|
destroy_pval(mon);
|
||||||
|
destroy_pval(s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
s->u1.str = (char *)include;
|
s->u1.str = (char *)include;
|
||||||
p->u1.list = linku1(p->u1.list, s);
|
p->u1.list = linku1(p->u1.list, s);
|
||||||
|
@ -5668,12 +5684,28 @@ char* pvalIfGetCondition( pval *p )
|
||||||
|
|
||||||
void pvalIfTimeSetCondition( pval *p, char *hour_range, char *dow_range, char *dom_range, char *mon_range ) /* time range format: 24-hour format begin-end|dow range|dom range|month range */
|
void pvalIfTimeSetCondition( pval *p, char *hour_range, char *dow_range, char *dom_range, char *mon_range ) /* time range format: 24-hour format begin-end|dow range|dom range|month range */
|
||||||
{
|
{
|
||||||
pval *hr = pvalCreateNode(PV_WORD);
|
pval *hr;
|
||||||
pval *dow = pvalCreateNode(PV_WORD);
|
pval *dow;
|
||||||
pval *dom = pvalCreateNode(PV_WORD);
|
pval *dom;
|
||||||
pval *mon = pvalCreateNode(PV_WORD);
|
pval *mon;
|
||||||
if (!pvalCheckType(p, "pvalIfTimeSetCondition", PV_IFTIME))
|
|
||||||
|
if (!pvalCheckType(p, "pvalIfTimeSetCondition", PV_IFTIME)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = pvalCreateNode(PV_WORD);
|
||||||
|
dow = pvalCreateNode(PV_WORD);
|
||||||
|
dom = pvalCreateNode(PV_WORD);
|
||||||
|
mon = pvalCreateNode(PV_WORD);
|
||||||
|
|
||||||
|
if (!hr || !dom || !dow || !mon) {
|
||||||
|
destroy_pval(hr);
|
||||||
|
destroy_pval(dom);
|
||||||
|
destroy_pval(dow);
|
||||||
|
destroy_pval(mon);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pvalWordSetString(hr, hour_range);
|
pvalWordSetString(hr, hour_range);
|
||||||
pvalWordSetString(dow, dow_range);
|
pvalWordSetString(dow, dow_range);
|
||||||
pvalWordSetString(dom, dom_range);
|
pvalWordSetString(dom, dom_range);
|
||||||
|
|
|
@ -410,10 +410,13 @@ static int load_file(const char *filename, char **ret)
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
len = ftell(f);
|
len = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
if (!(*ret = ast_malloc(len + 1)))
|
if (!(*ret = ast_malloc(len + 1))) {
|
||||||
|
fclose(f);
|
||||||
return -2;
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
if (len != fread(*ret, sizeof(char), len, f)) {
|
if (len != fread(*ret, sizeof(char), len, f)) {
|
||||||
|
fclose(f);
|
||||||
ast_free(*ret);
|
ast_free(*ret);
|
||||||
*ret = NULL;
|
*ret = NULL;
|
||||||
return -3;
|
return -3;
|
||||||
|
|
|
@ -429,7 +429,7 @@ static pjmedia_sdp_attr* generate_fmtp_attr(pj_pool_t *pool, struct ast_format *
|
||||||
*++tmp = '\0';
|
*++tmp = '\0';
|
||||||
/* ast...generate gives us everything, just need value */
|
/* ast...generate gives us everything, just need value */
|
||||||
tmp = strchr(ast_str_buffer(fmtp0), ':');
|
tmp = strchr(ast_str_buffer(fmtp0), ':');
|
||||||
if (tmp && tmp + 1) {
|
if (tmp && tmp[1] != '\0') {
|
||||||
fmtp1 = pj_str(tmp + 1);
|
fmtp1 = pj_str(tmp + 1);
|
||||||
} else {
|
} else {
|
||||||
fmtp1 = pj_str(ast_str_buffer(fmtp0));
|
fmtp1 = pj_str(ast_str_buffer(fmtp0));
|
||||||
|
|
Loading…
Reference in New Issue