Skip to content

Commit d9c49ff

Browse files
committed
confd: Validate container mount source path
If an invalid mount source path is specified, the container logs a "file not found" error and subsequently crashes. Adding a check inside the SR_EV_CHANGE event handler performs an early validation of the mount source path, allowing to reject configurations that reference non-existent or unreadable files before they are committed to the datastore.
1 parent 34456e9 commit d9c49ff

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/confd/src/infix-containers.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,35 @@ static int change(sr_session_ctx_t *session, uint32_t sub_id, const char *module
250250
switch (event) {
251251
case SR_EV_DONE:
252252
break;
253+
253254
case SR_EV_CHANGE:
255+
err = sr_get_data(session, CFG_XPATH "//.", 0, 0, 0, &cfg);
256+
if (err || !cfg)
257+
return SR_ERR_INTERNAL;
258+
259+
cifs = lydx_get_descendant(cfg->tree, "containers", "container", NULL);
260+
LYX_LIST_FOR_EACH(cifs, cif, "container") {
261+
struct lyd_node *mount;
262+
LYX_LIST_FOR_EACH(lyd_child(cif), mount, "mount") {
263+
const char *src = lydx_get_cattr(mount, "source");
264+
const char *id = lydx_get_cattr(mount, "name");
265+
266+
if (src && access(src, R_OK) != 0) {
267+
char errmsg[256];
268+
const char *reason = strerror(errno);
269+
snprintf(errmsg, sizeof(errmsg),
270+
"Container '%s': mount '%s' source file '%s' is invalid: %s",
271+
lydx_get_cattr(cif, "name"), id, src, reason);
272+
sr_session_set_error_message(session, errmsg);
273+
sr_release_data(cfg);
274+
return SR_ERR_VALIDATION_FAILED;
275+
}
276+
}
277+
}
278+
279+
sr_release_data(cfg);
280+
return SR_ERR_OK;
281+
254282
case SR_EV_ABORT:
255283
default:
256284
return SR_ERR_OK;

0 commit comments

Comments
 (0)