Message ID | 20180208192328.16550-26-kwolf@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 2018-02-08 20:23, Kevin Wolf wrote: > Most callers have their own checks, but something like this should also > be checked centrally. As it happens, x-blockdev-create can pass negative > image sizes to format drivers (because there is no QAPI type that would > reject negative numbers) and triggers the check added by this patch. > > Signed-off-by: Kevin Wolf <kwolf@redhat.com> > --- > block.c | 5 +++++ > 1 file changed, 5 insertions(+) Reviewed-by: Max Reitz <mreitz@redhat.com>
diff --git a/block.c b/block.c index 725c33e53f..59e74a5ebc 100644 --- a/block.c +++ b/block.c @@ -3681,6 +3681,11 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, error_setg(errp, "No medium inserted"); return -ENOMEDIUM; } + if (offset < 0) { + error_setg(errp, "Image size cannot be negative"); + return -EINVAL; + } + if (!drv->bdrv_truncate) { if (bs->file && drv->is_filter) { return bdrv_truncate(bs->file, offset, prealloc, errp);
Most callers have their own checks, but something like this should also be checked centrally. As it happens, x-blockdev-create can pass negative image sizes to format drivers (because there is no QAPI type that would reject negative numbers) and triggers the check added by this patch. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- block.c | 5 +++++ 1 file changed, 5 insertions(+)