Yes, it is fixed.
2020년 8월 18일 화요일 오전 1시 0분 23초 UTC+9에 [email protected]님이 작성:
> As Wonsup Yoon reported in the issue #1095 following C++ trying
> to read large number of bytes from /dev/random fails:
>
> ```
> #include<fstream>
> #include<vector>
> #include<iostream>
>
> #define READ_BYTES (1LL << 31)
>
> int main(){
>
> std::ifstream file("/dev/urandom");
>
> std::vector<char> data(READ_BYTES);
> data[0] = 1;
> file.read(data.data(), READ_BYTES);
>
> std::cout << +data[0] << std::endl;
>
>
> return 0;
> }
> ```
>
> To make long story short (see the issue for more details)
> it turns out that the culprit is wron signature of uiomove()
> function that uses int instead of size_t for n parameter.
> This patch fixes it.
>
> Fixes #1095
>
> Signed-off-by: Waldemar Kozaczuk <[email protected]>
> ---
> fs/vfs/subr_uio.cc | 4 ++--
> include/osv/uio.h | 8 ++------
> 2 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/fs/vfs/subr_uio.cc b/fs/vfs/subr_uio.cc
> index bf138b8e..fdc89bd4 100644
> --- a/fs/vfs/subr_uio.cc
> +++ b/fs/vfs/subr_uio.cc
> @@ -41,13 +41,13 @@
> #include <osv/uio.h>
>
> int
> -uiomove(void *cp, int n, struct uio *uio)
> +uiomove(void *cp, size_t n, struct uio *uio)
> {
> assert(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
>
> while (n > 0 && uio->uio_resid) {
> struct iovec *iov = uio->uio_iov;
> - int cnt = iov->iov_len;
> + size_t cnt = iov->iov_len;
> if (cnt == 0) {
> uio->uio_iov++;
> uio->uio_iovcnt--;
> diff --git a/include/osv/uio.h b/include/osv/uio.h
> index 8e2951be..2c117e7c 100644
> --- a/include/osv/uio.h
> +++ b/include/osv/uio.h
> @@ -42,11 +42,7 @@ __BEGIN_DECLS
>
> enum uio_rw { UIO_READ, UIO_WRITE };
>
> -/*
> - * Safe default to prevent possible overflows in user code, otherwise
> could
> - * be SSIZE_T_MAX.
> - */
> -#define IOSIZE_MAX INT_MAX
> +#define IOSIZE_MAX SSIZE_MAX
>
> #undef UIO_MAXIOV
> #define UIO_MAXIOV 1024
> @@ -61,7 +57,7 @@ struct uio {
> enum uio_rw uio_rw; /* operation */
> };
>
> -int uiomove(void *cp, int n, struct uio *uio);
> +int uiomove(void *cp, size_t n, struct uio *uio);
>
> __END_DECLS
>
> --
> 2.26.2
>
>
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/osv-dev/7c039c53-b3c2-41eb-88f8-8a847bee3d5dn%40googlegroups.com.