hardening cvvs due to errors
This commit is contained in:
parent
1fb3f792b6
commit
44612c57d8
2 changed files with 17 additions and 13 deletions
|
|
@ -918,10 +918,11 @@ xml_free(cxobj *x)
|
||||||
if (x->x_cv)
|
if (x->x_cv)
|
||||||
cv_free(x->x_cv);
|
cv_free(x->x_cv);
|
||||||
for (i=0; i<x->x_childvec_len; i++){
|
for (i=0; i<x->x_childvec_len; i++){
|
||||||
xc = x->x_childvec[i];
|
if ((xc = x->x_childvec[i]) != NULL){
|
||||||
xml_free(xc);
|
xml_free(xc);
|
||||||
x->x_childvec[i] = NULL;
|
x->x_childvec[i] = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#if (XML_CHILD_HASH==1)
|
#if (XML_CHILD_HASH==1)
|
||||||
if (x->x_hash)
|
if (x->x_hash)
|
||||||
hash_free(x->x_hash);
|
hash_free(x->x_hash);
|
||||||
|
|
|
||||||
|
|
@ -464,14 +464,11 @@ xml2cvec(cxobj *xt,
|
||||||
char *body;
|
char *body;
|
||||||
char *reason = NULL;
|
char *reason = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
int i = 0;
|
|
||||||
int len = 0;
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
xc = NULL;
|
xc = NULL;
|
||||||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL)
|
/* Tried to allocate whole cvv here,but some cg_vars may be invalid */
|
||||||
len++;
|
if ((cvv = cvec_new(0)) == NULL){
|
||||||
if ((cvv = cvec_new(len)) == NULL){
|
|
||||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
@ -483,8 +480,10 @@ xml2cvec(cxobj *xt,
|
||||||
clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s",
|
clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s",
|
||||||
__FUNCTION__, name, yt->ys_argument);
|
__FUNCTION__, name, yt->ys_argument);
|
||||||
if ((body = xml_body(xc)) != NULL){
|
if ((body = xml_body(xc)) != NULL){
|
||||||
cv = cvec_i(cvv, i++);
|
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
|
||||||
cv_type_set(cv, CGV_STRING);
|
clicon_err(OE_PLUGIN, errno, "cvec_add");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
cv_name_set(cv, name);
|
cv_name_set(cv, name);
|
||||||
if ((ret = cv_parse1(body, cv, &reason)) < 0){
|
if ((ret = cv_parse1(body, cv, &reason)) < 0){
|
||||||
clicon_err(OE_PLUGIN, errno, "cv_parse");
|
clicon_err(OE_PLUGIN, errno, "cv_parse");
|
||||||
|
|
@ -498,11 +497,13 @@ xml2cvec(cxobj *xt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if ((ycv = ys->ys_cv) != NULL){
|
||||||
if ((ycv = ys->ys_cv) != NULL){
|
|
||||||
if ((body = xml_body(xc)) != NULL){
|
if ((body = xml_body(xc)) != NULL){
|
||||||
/* XXX: cvec_add uses realloc, can we avoid that? */
|
/* XXX: cvec_add uses realloc, can we avoid that? */
|
||||||
cv = cvec_i(cvv, i++);
|
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
|
||||||
|
clicon_err(OE_PLUGIN, errno, "cvec_add");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
if (cv_cp(cv, ycv) < 0){
|
if (cv_cp(cv, ycv) < 0){
|
||||||
clicon_err(OE_PLUGIN, errno, "cv_cp");
|
clicon_err(OE_PLUGIN, errno, "cv_cp");
|
||||||
goto err;
|
goto err;
|
||||||
|
|
@ -567,6 +568,8 @@ cvec2xml_1(cvec *cvv,
|
||||||
cv = NULL;
|
cv = NULL;
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((cv = cvec_each(cvv, cv)) != NULL) {
|
while ((cv = cvec_each(cvv, cv)) != NULL) {
|
||||||
|
if (cv_type_get(cv)==CGV_ERR || cv_name_get(cv) == NULL)
|
||||||
|
continue;
|
||||||
if ((xn = xml_new(cv_name_get(cv), NULL)) == NULL) /* this leaks */
|
if ((xn = xml_new(cv_name_get(cv), NULL)) == NULL) /* this leaks */
|
||||||
goto err;
|
goto err;
|
||||||
xml_parent_set(xn, xt);
|
xml_parent_set(xn, xt);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue