Skip to content

Commit

Permalink
tool_cb_wrt: fix writing to Windows null device NUL
Browse files Browse the repository at this point in the history
- Improve console detection.

Prior to this change WriteConsole could be called to write to a handle
that may not be a console, which would cause an error. This issue is
limited to character devices that are not also consoles such as the null
device NUL.

Bug: curl#3175 (comment)
Reported-by: Gisle Vanem
  • Loading branch information
jay committed Mar 26, 2019
1 parent 2bcdf72 commit f5bc578
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/tool_cb_wrt.c
Expand Up @@ -79,6 +79,9 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
struct OperationConfig *config = outs->config;
size_t bytes = sz * nmemb;
bool is_tty = config->global->isatty;
#ifdef WIN32
CONSOLE_SCREEN_BUFFER_INFO console_info;
#endif

/*
* Once that libcurl has called back tool_write_cb() the returned value
Expand Down Expand Up @@ -156,7 +159,9 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
}

#ifdef _WIN32
if(isatty(fileno(outs->stream))) {
if(isatty(fileno(outs->stream)) &&
GetConsoleScreenBufferInfo(
(HANDLE)_get_osfhandle(fileno(outs->stream)), &console_info)) {
DWORD in_len = (DWORD)(sz * nmemb);
wchar_t* wc_buf;
DWORD wc_len;
Expand Down

0 comments on commit f5bc578

Please sign in to comment.