From 0da4a635bc00a5a0791b3fb96d5121679328dfec Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 18 May 2017 08:27:27 +0200 Subject: [PATCH] virStream: Forbid negative seeks Currently, we don't assign any meaning to that. Our current view on virStream is that it's merely a pipe. And pipes don't support seeking. Signed-off-by: Michal Privoznik --- src/internal.h | 7 +++++++ src/rpc/virnetclientstream.c | 1 + src/util/virfdstream.c | 1 + 3 files changed, 9 insertions(+) diff --git a/src/internal.h b/src/internal.h index 5a5a430a26..9e7ef553d7 100644 --- a/src/internal.h +++ b/src/internal.h @@ -527,6 +527,13 @@ goto label; \ } \ } while (0) +# define virCheckPositiveArgReturn(argname, retval) \ + do { \ + if (argname <= 0) { \ + virReportInvalidPositiveArg(argname); \ + return retval; \ + } \ + } while (0) # define virCheckNonZeroArgGoto(argname, label) \ do { \ if (argname == 0) { \ diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 7b28d63db0..a9bf271dc5 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -367,6 +367,7 @@ virNetClientStreamSetHole(virNetClientStreamPtr st, unsigned int flags) { virCheckFlags(0, -1); + virCheckPositiveArgReturn(length, -1); /* Shouldn't happen, But it's better to safe than sorry. */ if (st->holeLength) { diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 6870d8846c..7ee58be136 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -950,6 +950,7 @@ virFDStreamSendHole(virStreamPtr st, int ret = -1; virCheckFlags(0, -1); + virCheckPositiveArgReturn(length, -1); virObjectLock(fdst); if (fdst->length) {