Re: [PATCH v5 3/8] vfio: selftests: Introduce a sysfs lib

From: Raghavendra Rao Ananta

Date: Tue Mar 03 2026 - 11:28:14 EST


On Fri, Feb 27, 2026 at 3:39 PM Raghavendra Rao Ananta
<rananta@xxxxxxxxxx> wrote:
> +
> +char *sysfs_sriov_vf_bdf_get(const char *pf_bdf, int i)
> +{
> + char vf_path[PATH_MAX];
> + char path[PATH_MAX];
> + char *out_vf_bdf;
> + int ret;
> +
> + out_vf_bdf = calloc(16, sizeof(char));
> + VFIO_ASSERT_NOT_NULL(out_vf_bdf);
> +
> + snprintf_assert(path, PATH_MAX, "/sys/bus/pci/devices/%s/virtfn%d", pf_bdf, i);
> +
> + ret = readlink(path, vf_path, PATH_MAX);
> + VFIO_ASSERT_NE(ret, -1);
> +
In one of the recent runs (with some other local changes), I see
'vf_path' still holds the contents from a previous stack frame,
appended at the end.
readlink() man page mentions that the output buf is not '\0'
terminated and the reason why I'm running into this. Either we
terminate it explicitly or initialize 'vf_path' with an empty string.
I'll send out a v6 with the first approach taking care of this
wherever readlink() is used.

Thank you.
Raghavendra