Date: Tue, 3 Dec 2019 09:48:43 +0000 (UTC) From: Andriy Gapon <avg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355325 - head/lib/libdevstat Message-ID: <201912030948.xB39mhlw038262@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: avg Date: Tue Dec 3 09:48:43 2019 New Revision: 355325 URL: https://svnweb.freebsd.org/changeset/base/355325 Log: devstat_selectdevs: resize dev_select only after copying data out of it The resizing could be a downsizing so some data would be lost and we could attempt to read past the end of the new memory allocation. MFC after: 2 weeks Sponsored by: Panzura Modified: head/lib/libdevstat/devstat.c Modified: head/lib/libdevstat/devstat.c ============================================================================== --- head/lib/libdevstat/devstat.c Tue Dec 3 09:12:53 2019 (r355324) +++ head/lib/libdevstat/devstat.c Tue Dec 3 09:48:43 2019 (r355325) @@ -584,10 +584,10 @@ devstat_selectdevs(struct device_selection **dev_selec * In this case, we have selected devices before, but the device * list has changed since we last selected devices, so we need to * either enlarge or reduce the size of the device selection list. + * But delay the resizing until after copying the data to old_dev_select + * as to not lose any data in the case of reducing the size. */ } else if (*num_selections != numdevs) { - *dev_select = (struct device_selection *)reallocf(*dev_select, - numdevs * sizeof(struct device_selection)); *select_generation = current_generation; init_selections = 1; /* @@ -643,6 +643,11 @@ devstat_selectdevs(struct device_selection **dev_selec old_num_selections = *num_selections; bcopy(*dev_select, old_dev_select, sizeof(struct device_selection) * *num_selections); + } + + if (!changed && *num_selections != numdevs) { + *dev_select = (struct device_selection *)reallocf(*dev_select, + numdevs * sizeof(struct device_selection)); } if (init_selections != 0) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912030948.xB39mhlw038262>