The routine “options_from_info” does not preserve the “cookie” field when a version 0 “struct lcb_create_io_ops_st” is passed to lcb_create_io_ops().
I began experiencing segmentation faults when I began using libcouchbase 2.1.0 that were not present when I used version 2.0.7. I tracked the problem to the following routine, which was added in commit 21e01538bda64048964dbfb7a8b0191be5c44441.
This routine:
static void options_from_info(struct lcb_create_io_ops_st *opts,
const plugin_info *info)
{
if (info->create) {
opts->version = 2;
opts->v.v2.create = info->create;
return;
}
opts->version = 1;
opts->v.v1.sofile = info->soname;
opts->v.v1.symbol = info->symbol;
}
does not preserve the cookie, causing a subsequent segmentation fault.
For testing purposes, I replaced it with the following:
static void options_from_info(struct lcb_create_io_ops_st *opts,
const plugin_info *info)
{
void *cookie;
if (info->create) {
opts->version = 2;
opts->v.v2.create = info->create;
return;
}
if (opts->version == 0) {
cookie = opts->v.v0.cookie;
opts->v.v1.cookie = cookie;
}
opts->version = 1;
opts->v.v1.sofile = info->soname;
opts->v.v1.symbol = info->symbol;
}
which fixed my issue.