Adjusted code to not rely on COMPAT_6_5 API

Leak in optimize xpath code
This commit is contained in:
Olof hagsand 2024-03-14 15:20:00 +01:00
parent d3587b8646
commit 59b3100704
5 changed files with 31 additions and 25 deletions

View file

@ -116,6 +116,9 @@ int clixon_err_restore(void *handle);
int clixon_err_cat_reg(enum clixon_err category, void *handle, clixon_cat_log_cb logfn);
int clixon_err_exit(void);
/* doesnt work if arg != NULL */
#define clixon_netconf_error(h, x, f, a) clixon_err_fn((h), __FUNCTION__, __LINE__, OE_XML, 0,(x), (f))
#if 1 /* COMPAT_6_5 */
#define clicon_err(c,s,_fmt, args...) clixon_err_fn(NULL, __FUNCTION__, __LINE__, (c), (s), NULL, _fmt , ##args)
#define clicon_err_reset() clixon_err_reset()
@ -124,9 +127,7 @@ int clixon_err_exit(void);
#define clicon_suberrno clixon_err_subnr()
#define clicon_err_reason clixon_err_reason()
/* doesnt work if arg != NULL */
#define clixon_netconf_error(h, x, f, a) clixon_err_fn((h), __FUNCTION__, __LINE__, OE_XML, 0,(x), (f) , NULL)
#endif
#endif /* _CLIXON_ERR_H_ */

View file

@ -354,7 +354,7 @@ clixon_err_args(clixon_handle h,
* printf("%s", cbuf_get(cb));
* cbuf_free(cb);
* @endcode
* @see clixon_err_netconf_fn
* @see clixon_error_netconf
*/
int
netconf_err2cb(clixon_handle h,
@ -409,7 +409,7 @@ netconf_err2cb(clixon_handle h,
* @param[in] format Error string, format with argv
* @retval 0 OK
* @retval -1 Error
* @see clixon_err_netconf_fn For variant with netconf error message
* @see clixon_netconf_error For variant with netconf error message
*/
int
clixon_err_fn(clixon_handle h,

View file

@ -492,6 +492,7 @@ api_path_fmt_subst_list_key(cbuf *cb,
* api_path: /interfaces/interface=e/ipv4/address=1.2.3.4
* @param[in] api_path_fmt XML key format, eg /aaa/%s/name
* @param[in] cvv cligen variable vector, one for every wildchar in api_path_fmt
* @param[in] yspec
* @param[out] api_path api_path, eg /aaa/17. Free after use
* @param[out] cvv_i 1..cvv-len. Index into cvv of last cvv entry used, For example,
* if same as len of cvv, all were used, if < some entries were not

View file

@ -407,8 +407,8 @@ clixon_msg_send(int s,
clixon_debug(CLIXON_DBG_MSG, "Send: %s", cbuf_get(cb));
if (atomicio((ssize_t (*)(int, void *, size_t))write,
s, cbuf_get(cb), cbuf_len(cb)) < 0){
clicon_err(OE_CFG, errno, "atomicio");
clicon_log(LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno));
clixon_err(OE_CFG, errno, "atomicio");
clixon_log(NULL, LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno));
goto done;
}
retval = 0;
@ -613,7 +613,7 @@ clixon_msg_rcv11(int s,
struct sigaction oldsigaction[32] = {{{0,},},};
if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
clixon_err(OE_XML, errno, "cbuf_new");
goto done;
}
eom = 0;
@ -707,7 +707,7 @@ clicon_rpc(int sock,
goto ok;
if (cbrcv){
if ((*ret = strdup(cbuf_get(cbrcv))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
clixon_err(OE_UNIX, errno, "strdup");
goto done;
}
cbuf_free(cbrcv);
@ -740,11 +740,11 @@ send_msg_reply(int s,
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (cbuf_append_buf(cb, data, datalen) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_buf");
clixon_err(OE_UNIX, errno, "cbuf_append_buf");
goto done;
}
if (clixon_msg_send11(s, descr, cb) < 0)
@ -774,7 +774,7 @@ send_msg_notify(int s,
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
cprintf(cb, "%s", msg);

View file

@ -333,27 +333,31 @@ xpath_optimize_check(xpath_tree *xs,
int *xlen0)
{
#ifdef XPATH_LIST_OPTIMIZE
int retval = -1;
int ret;
clixon_xvec *xvec = NULL;
if (!_optimize_enable)
return 0; /* use regular code */
if ((xvec = clixon_xvec_new()) == NULL)
return -1;
goto ok;
else if ((xvec = clixon_xvec_new()) == NULL)
goto done;
/* Glue code since xpath code uses (old) cxobj ** and search code uses (new) clixon_xvec */
if ((ret = xpath_list_optimize_fn(xs, xv, xvec)) < 0)
return -1;
if (ret == 1){
if (clixon_xvec_extract(xvec, xvec0, xlen0, NULL) < 0)
return -1;
clixon_xvec_free(xvec);
else if ((ret = xpath_list_optimize_fn(xs, xv, xvec)) < 0)
goto done;
else if (ret == 1){
if (clixon_xvec_extract(xvec, xvec0, xlen0, NULL) < 0){
goto done;
}
_optimize_hits++;
return 1; /* Optimized */
retval = 1; /* Optimized */
goto done;
}
else{
ok:
retval = 0; /* use regular code */
done:
if (xvec)
clixon_xvec_free(xvec);
return 0; /* use regular code */
}
return retval;
#else
return 0; /* use regular code */
#endif