From 1e6188d774e8dc9c74be1d130ece23062faf4308 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 20 Jun 2020 18:43:36 +0200 Subject: [PATCH] Check the return value from pipe(2) Starting from GCC 10 not checking this will produce a warning. --- src/wine-host/bridges/group.cpp | 4 +++- src/wine-host/bridges/group.h | 3 +++ src/wine-host/group-host.cpp | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wine-host/bridges/group.cpp b/src/wine-host/bridges/group.cpp index b464c3d8..f034bcda 100644 --- a/src/wine-host/bridges/group.cpp +++ b/src/wine-host/bridges/group.cpp @@ -66,7 +66,9 @@ StdIoCapture::StdIoCapture(boost::asio::io_context& io_context, original_fd_copy(dup(file_descriptor)) { // We'll use the second element of these two file descriptors to reopen // `file_descriptor`, and the first one to read the captured contents from - ::pipe(pipe_fd); + if (::pipe(pipe_fd) != 0) { + throw std::system_error(errno, std::system_category()); + } // We've already created a copy of the original file descriptor, so we can // reopen it using the newly created pipe diff --git a/src/wine-host/bridges/group.h b/src/wine-host/bridges/group.h index 9768daef..c926cd9c 100644 --- a/src/wine-host/bridges/group.h +++ b/src/wine-host/bridges/group.h @@ -45,6 +45,8 @@ class StdIoCapture { * * @param io_context The IO context to create the captured pipe stream on. * @param file_descriptor The file descriptor to remap. + * + * @throw std::system_error If the pipe could not be created. */ StdIoCapture(boost::asio::io_context& io_context, int file_descriptor); @@ -111,6 +113,7 @@ class GroupBridge { * `create_logger_prefix()` function in `./group.cpp`. * * @throw boost::system::system_error If we can't listen on the socket. + * @throw std::system_error If the pipe could not be created. * * @note Creating an `GroupBridge` instance has the side effect that the * STDOUT and STDERR streams of the current process will be redirected to diff --git a/src/wine-host/group-host.cpp b/src/wine-host/group-host.cpp index 41ad89a7..abc72e95 100644 --- a/src/wine-host/group-host.cpp +++ b/src/wine-host/group-host.cpp @@ -78,6 +78,11 @@ int __cdecl main(int argc, char* argv[]) { << std::endl; std::cerr << error.what() << std::endl; + return 0; + } catch (const std::system_error& error) { + std::cerr << "Could not create pipe:" << std::endl; + std::cerr << error.what() << std::endl; + return 0; } }