CESNET / libnetconf

C NETCONF library
Other
113 stars 83 forks source link

A bug in file_rollback_restore() #236

Closed classcwnd closed 7 years ago

classcwnd commented 7 years ago

Hi,

I think in file_rollback_restore(), we need to rebuild running, candidate and startup pointers in file_ds by calling file_fill_dsnodes(). Because the xml of file_ds has been changed to xml_rollback. Otherwise, running, candidate and startup pointers shall be pointed to illegal memory if old xml is released. We has found such issue in tests.

static int file_rollback_restore(struct ncds_ds_file* file_ds)
{
    if (file_ds == NULL || !file_ds->ds_lock.holding_lock) {
        ERROR("%s: invalid parameter.", __func__);
        return (EXIT_FAILURE);
    }

    if (file_ds->xml_rollback == NULL) {
        ERROR("No backup repository for rollback operation (datastore %d).", file_ds->ds.id);
        return (EXIT_FAILURE);
    }

    xmlFreeDoc(file_ds->xml);
    file_ds->xml = file_ds->xml_rollback;
    file_ds->xml_rollback = NULL;
    file_ds->ds.last_access = 0;

    return (file_sync(file_ds));
}