Skip to content

Commit 94b9b66

Browse files
committed
shm sub BUGFIX safe xpath collect
Pointers to ext SHM are not safe.
1 parent 3832743 commit 94b9b66

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/modinfo.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ sr_modinfo_oper_notify_diff(struct sr_mod_info_s *mod_info, struct lyd_node **ol
754754
struct sr_mod_info_mod_s *mod;
755755
struct lyd_node *new_mod_data = NULL, *old_mod_data = NULL, *diff;
756756
uint32_t i;
757-
const char **xpaths = NULL;
757+
char **xpaths = NULL;
758758

759759
assert(!mod_info->notify_diff && !mod_info->data_cached);
760760

@@ -782,7 +782,7 @@ sr_modinfo_oper_notify_diff(struct sr_mod_info_s *mod_info, struct lyd_node **ol
782782
xpaths = NULL;
783783

784784
/* merge also any stored data used in change subscription xpath filters so they can be correctly evaluated */
785-
if ((err_info = sr_shmsub_change_collect_xpath(mod_info->conn, mod->shm_mod, SR_DS_OPERATIONAL, &xpaths))) {
785+
if ((err_info = sr_shmsub_change_xpath_collect(mod_info->conn, mod->shm_mod, SR_DS_OPERATIONAL, &xpaths))) {
786786
goto cleanup;
787787
}
788788
if ((err_info = sr_xpath_merge_pred_diff(new_mod_data, (const char **)xpaths, &mod_info->notify_diff))) {
@@ -804,7 +804,7 @@ sr_modinfo_oper_notify_diff(struct sr_mod_info_s *mod_info, struct lyd_node **ol
804804
cleanup:
805805
lyd_free_all(new_mod_data);
806806
lyd_free_all(old_mod_data);
807-
free(xpaths);
807+
sr_shmsub_change_xpath_free(xpaths);
808808
return err_info;
809809
}
810810

@@ -3494,23 +3494,23 @@ sr_error_info_t *
34943494
sr_modinfo_change_diff_merge_pred_data(struct sr_mod_info_s *mod_info)
34953495
{
34963496
sr_error_info_t *err_info = NULL;
3497-
const char **xpaths = NULL;
3497+
char **xpaths = NULL;
34983498
uint32_t i;
34993499

35003500
/* collect all the xpaths of the subscriptions */
35013501
for (i = 0; i < mod_info->mod_count; ++i) {
3502-
if ((err_info = sr_shmsub_change_collect_xpath(mod_info->conn, mod_info->mods[i].shm_mod, mod_info->ds, &xpaths))) {
3502+
if ((err_info = sr_shmsub_change_xpath_collect(mod_info->conn, mod_info->mods[i].shm_mod, mod_info->ds, &xpaths))) {
35033503
goto cleanup;
35043504
}
35053505
}
35063506

35073507
/* merge all the required data into the diff */
3508-
if ((err_info = sr_xpath_merge_pred_diff(mod_info->data, xpaths, &mod_info->notify_diff))) {
3508+
if ((err_info = sr_xpath_merge_pred_diff(mod_info->data, (const char **)xpaths, &mod_info->notify_diff))) {
35093509
goto cleanup;
35103510
}
35113511

35123512
cleanup:
3513-
free(xpaths);
3513+
sr_shmsub_change_xpath_free(xpaths);
35143514
return err_info;
35153515
}
35163516

src/shm_sub.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ sr_shmsub_change_notify_change_abort(struct sr_mod_info_s *mod_info, const char
22092209
}
22102210

22112211
sr_error_info_t *
2212-
sr_shmsub_change_collect_xpath(sr_conn_ctx_t *conn, sr_mod_t *shm_mod, sr_datastore_t ds, const char ***xpaths)
2212+
sr_shmsub_change_xpath_collect(sr_conn_ctx_t *conn, sr_mod_t *shm_mod, sr_datastore_t ds, char ***xpaths)
22132213
{
22142214
sr_error_info_t *err_info = NULL;
22152215
sr_mod_change_sub_t *shm_sub;
@@ -2240,7 +2240,9 @@ sr_shmsub_change_collect_xpath(sr_conn_ctx_t *conn, sr_mod_t *shm_mod, sr_datast
22402240
/* add the xpath */
22412241
*xpaths = sr_realloc(*xpaths, (xpath_count + 2) * sizeof **xpaths);
22422242
SR_CHECK_MEM_GOTO(!*xpaths, err_info, cleanup);
2243-
(*xpaths)[xpath_count++] = conn->ext_shm.addr + shm_sub[i].xpath;
2243+
(*xpaths)[xpath_count] = strdup(conn->ext_shm.addr + shm_sub[i].xpath);
2244+
SR_CHECK_MEM_GOTO(!(*xpaths)[xpath_count], err_info, cleanup);
2245+
xpath_count++;
22442246
(*xpaths)[xpath_count] = NULL;
22452247
}
22462248

@@ -2251,6 +2253,21 @@ sr_shmsub_change_collect_xpath(sr_conn_ctx_t *conn, sr_mod_t *shm_mod, sr_datast
22512253
return err_info;
22522254
}
22532255

2256+
void
2257+
sr_shmsub_change_xpath_free(char **xpaths)
2258+
{
2259+
uint32_t i;
2260+
2261+
if (!xpaths) {
2262+
return;
2263+
}
2264+
2265+
for (i = 0; xpaths[i]; ++i) {
2266+
free(xpaths[i]);
2267+
}
2268+
free(xpaths);
2269+
}
2270+
22542271
sr_error_info_t *
22552272
sr_shmsub_oper_get_notify(struct sr_mod_info_mod_s *mod, const char *xpath, const char *request_xpath,
22562273
const struct lyd_node *parent, const char *orig_name, const void *orig_data, uint32_t operation_id,

src/shm_sub.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ sr_error_info_t *sr_shmsub_change_notify_change_abort(struct sr_mod_info_s *mod_
170170
* @param[in,out] xpaths Array of XPaths terminated by NULL to add to.
171171
* @return err_info, NULL on success.
172172
*/
173-
sr_error_info_t *sr_shmsub_change_collect_xpath(sr_conn_ctx_t *conn, sr_mod_t *shm_mod, sr_datastore_t ds,
174-
const char ***xpaths);
173+
sr_error_info_t *sr_shmsub_change_xpath_collect(sr_conn_ctx_t *conn, sr_mod_t *shm_mod, sr_datastore_t ds,
174+
char ***xpaths);
175+
176+
/**
177+
* @brief Free collected XPath filters of module change subscriptions.
178+
*
179+
* @param[in] xpaths XPaths array to free.
180+
*/
181+
void sr_shmsub_change_xpath_free(char **xpaths);
175182

176183
/**
177184
* @brief Notify about (generate) an operational get event.

0 commit comments

Comments
 (0)