Skip to contentSkip to conversation

uninitialized handle fix (serious issue on Win 8.1)

Openvpn-devel Илья Шипицин 2 participants 6 messages Dec 4, 2013 – Dec 6, 2013

lore
Share & tools
lore
#0 lore raw

Hello!

I confirm issue described here: https://forums.openvpn.net/topic13246.html
also, I confirm that it is due to random handle value (which somehow was null before Win 8.1 was released)

also, I do not understand why we should check "err" handle on INVALID_HANDLE_VALUE, it will fail anyway on WriteFile, that check is useless.

I do not insist on being perfect, if someone has better idea how to solve https://forums.openvpn.net/topic13246.html - I do not mind.

I can make git pull request from
https://github.com/chipitsine/openvpn/commit/3987bd0e035b653a5017c5eccbd54eaf22746852
if it's better.

people encounter problems on Win 8.1 (well, just couple of people here, we are running openvpn with tens of customers on Win 8.1), I beleive it is serious issue, please consider release of openvpn.

src/openvpn/console.c +0 -0
index afda8ca..3ec5758 100644
@@ -62,7 +62,6 @@ get_console_input_win32 (const char *prompt, const

bool echo, char *input, const
err = get_orig_stderr ();

if (in != INVALID_HANDLE_VALUE
- && err != INVALID_HANDLE_VALUE

       && !win32_service_interrupt (&win32_signal)
       && WriteFile (err, prompt, strlen (prompt), &len, NULL))
     {
src/openvpn/error.c +2 -2
index 6848425..acc7977 100644
@@ -454,12 +454,12 @@ close_syslog ()
 
 #ifdef WIN32
 
-static HANDLE orig_stderr;
+static HANDLE orig_stderr = INVALID_HANDLE_VALUE;
 
 HANDLE
 get_orig_stderr (void)
 {
-  if (orig_stderr)
+  if (orig_stderr != INVALID_HANDLE_VALUE)
     return orig_stderr;
   else
     return GetStdHandle (STD_ERROR_HANDLE);
#1 lore raw

guys, please pay attention to this message. it really resolves issue with openvpn on windows 8.1

---------- Forwarded message ----------
From: Илья Шипицин <[email protected]...>
Date: 2013/12/4
Subject: uninitialized handle fix (serious issue on Win 8.1)
To: "[email protected]" <[email protected]>

Hello!

I confirm issue described here: https://forums.openvpn.net/topic13246.html
also, I confirm that it is due to random handle value (which somehow was null before Win 8.1 was released)

also, I do not understand why we should check "err" handle on INVALID_HANDLE_VALUE, it will fail anyway on WriteFile, that check is useless.

I do not insist on being perfect, if someone has better idea how to solve https://forums.openvpn.net/topic13246.html - I do not mind.

I can make git pull request from
https://github.com/chipitsine/openvpn/commit/3987bd0e035b653a5017c5eccbd54eaf22746852
if it's better.

people encounter problems on Win 8.1 (well, just couple of people here, we are running openvpn with tens of customers on Win 8.1), I beleive it is serious issue, please consider release of openvpn.

src/openvpn/console.c +0 -0
index afda8ca..3ec5758 100644
@@ -62,7 +62,6 @@ get_console_input_win32 (const char *prompt, const

bool echo, char *input, const
err = get_orig_stderr ();

if (in != INVALID_HANDLE_VALUE
- && err != INVALID_HANDLE_VALUE

       && !win32_service_interrupt (&win32_signal)
       && WriteFile (err, prompt, strlen (prompt), &len, NULL))
     {
src/openvpn/error.c +2 -2
index 6848425..acc7977 100644
@@ -454,12 +454,12 @@ close_syslog ()
 
 #ifdef WIN32
 
-static HANDLE orig_stderr;
+static HANDLE orig_stderr = INVALID_HANDLE_VALUE;
 
 HANDLE
 get_orig_stderr (void)
 {
-  if (orig_stderr)
+  if (orig_stderr != INVALID_HANDLE_VALUE)
     return orig_stderr;
   else
     return GetStdHandle (STD_ERROR_HANDLE);
#2 lore raw

[Openvpn-devel] NAK on uninitialized handle fix (serious issue on Win 8.1)

In reply to Илья Шипицин

Am 04.12.2013 14:12, schrieb Илья Шипицин:

Quoted 29 lines

Hello!

I confirm issue described here: https://forums.openvpn.net/topic13246.html
also, I confirm that it is due to random handle value (which somehow was null before Win 8.1 was released)

also, I do not understand why we should check "err" handle on INVALID_HANDLE_VALUE, it will fail anyway on WriteFile, that check is useless.

I do not insist on being perfect, if someone has better idea how to solve https://forums.openvpn.net/topic13246.html - I do not mind.

I can make git pull request from
https://github.com/chipitsine/openvpn/commit/3987bd0e035b653a5017c5eccbd54eaf22746852
if it's better.

people encounter problems on Win 8.1 (well, just couple of people here, we are running openvpn with tens of customers on Win 8.1), I beleive it is serious issue, please consider release of openvpn.

src/openvpn/console.c +0 -0
index afda8ca..3ec5758 100644
@@ -62,7 +62,6 @@ get_console_input_win32 (const char *prompt, const

bool echo, char *input, const
err = get_orig_stderr ();

Quoted 5 lines
   if (in != INVALID_HANDLE_VALUE
-      && err != INVALID_HANDLE_VALUE
       && !win32_service_interrupt (&win32_signal)
       && WriteFile (err, prompt, strlen (prompt), &len, NULL))
     {

Ilya, I am sorry to have to veto this for now.

NAK from me, this introduces a new bug. If GetStdError() inside get_orig_stderr() fails, you will end up with err == INVALID_HANDLE_VALUE here, so the check err != INVALID_HANDLE_VALUE must not be removed.

Similarly, if get_orig_stderr() returns NULL, you must not call WriteFile() either, so how about an additional "&& err != NULL" here?

I don't have Win 8.1 and cannot test that.

Quoted 10 lines
src/openvpn/error.c +0 -1
index 6848425..acc7977 100644
@@ -454,12 +454,12 @@ close_syslog ()
 
 #ifdef WIN32
 
-static HANDLE orig_stderr;

src/openvpn/error.c close_syslog () · line 465

Quoted 10 lines
src/openvpn/error.c +2 -1
+static HANDLE orig_stderr = INVALID_HANDLE_VALUE;
 
 HANDLE
 get_orig_stderr (void)
 {
-  if (orig_stderr)
+  if (orig_stderr != INVALID_HANDLE_VALUE)
     return orig_stderr;
   else
     return GetStdHandle (STD_ERROR_HANDLE);

NAK on this, too. It exchanges one bug for another.

The STD_ERROR_HANDLE interface has, according to
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx>,
two special values, INVALID_HANDLE_VALUE (as error marker) and NULL (as marker for "we don't have a console").

I think that there needs to be a separate/new "orig_stderr_is_valid" variable, or at least the if (...) else needs to be

if (orig_stderr != NULL && orig_stderr != INVALID_HANDLE_VALUE)
...

#3 lore raw

Re: [Openvpn-devel] NAK on uninitialized handle fix (serious issue on Win 8.1)

2013/12/6 Matthias Andree <[email protected]...>:

Quoted 38 lines

Am 04.12.2013 14:12, schrieb Илья Шипицин:

Quoted 29 lines

Hello!

I confirm issue described here: https://forums.openvpn.net/topic13246.html
also, I confirm that it is due to random handle value (which somehow was null before Win 8.1 was released)

also, I do not understand why we should check "err" handle on INVALID_HANDLE_VALUE, it will fail anyway on WriteFile, that check is useless.

I do not insist on being perfect, if someone has better idea how to solve https://forums.openvpn.net/topic13246.html - I do not mind.

I can make git pull request from
https://github.com/chipitsine/openvpn/commit/3987bd0e035b653a5017c5eccbd54eaf22746852
if it's better.

people encounter problems on Win 8.1 (well, just couple of people here, we are running openvpn with tens of customers on Win 8.1), I beleive it is serious issue, please consider release of openvpn.

src/openvpn/console.c +0 -0
index afda8ca..3ec5758 100644
@@ -62,7 +62,6 @@ get_console_input_win32 (const char *prompt, const

bool echo, char *input, const
err = get_orig_stderr ();

Quoted 5 lines
   if (in != INVALID_HANDLE_VALUE
-      && err != INVALID_HANDLE_VALUE
       && !win32_service_interrupt (&win32_signal)
       && WriteFile (err, prompt, strlen (prompt), &len, NULL))
     {

Ilya, I am sorry to have to veto this for now.

Quoted 2 lines

NAK from me, this introduces a new bug. If GetStdError() inside get_orig_stderr() fails, you will end up with err ==

no.

get_orig_stderr() first tries "if (orig_stderr)" which is ok if variable orig_stderr was proper initialized.
if error redirection is not requested, that check could give unpredictable result because orig_stderr was not initialized.

it was ok on windows before win 8.1, I beleive uninitized variabled were actually initialized by NULL

Quoted 3 lines

INVALID_HANDLE_VALUE here, so the check err != INVALID_HANDLE_VALUE must not be removed.

check (err != INVALID_HANDLE_VALUE) is cosmetic and it is not actually related to bugfix.
the idea is "why to check err againt INVALID_HANDLE_VALUE, if WriteFile would fail anyway under such condition"

Quoted 48 lines

Similarly, if get_orig_stderr() returns NULL, you must not call WriteFile() either, so how about an additional "&& err != NULL" here?

I don't have Win 8.1 and cannot test that.

Quoted 10 lines
src/openvpn/error.c +0 -1
index 6848425..acc7977 100644
@@ -454,12 +454,12 @@ close_syslog ()
 
 #ifdef WIN32
 
-static HANDLE orig_stderr;

src/openvpn/error.c close_syslog () · line 465

Quoted 10 lines
src/openvpn/error.c +2 -1
+static HANDLE orig_stderr = INVALID_HANDLE_VALUE;
 
 HANDLE
 get_orig_stderr (void)
 {
-  if (orig_stderr)
+  if (orig_stderr != INVALID_HANDLE_VALUE)
     return orig_stderr;
   else
     return GetStdHandle (STD_ERROR_HANDLE);

NAK on this, too. It exchanges one bug for another.

The STD_ERROR_HANDLE interface has, according to
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx>,
two special values, INVALID_HANDLE_VALUE (as error marker) and NULL (as marker for "we don't have a console").

I think that there needs to be a separate/new "orig_stderr_is_valid" variable, or at least the if (...) else needs to be

if (orig_stderr != NULL && orig_stderr != INVALID_HANDLE_VALUE)
...

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base. Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#4 lore raw

Re: [Openvpn-devel] NAK on uninitialized handle fix (serious issue on Win 8.1)

In reply to Matthias Andree

2013/12/6 Matthias Andree <[email protected]...>:

Quoted 38 lines

Am 04.12.2013 14:12, schrieb Илья Шипицин:

Quoted 29 lines

Hello!

I confirm issue described here: https://forums.openvpn.net/topic13246.html
also, I confirm that it is due to random handle value (which somehow was null before Win 8.1 was released)

also, I do not understand why we should check "err" handle on INVALID_HANDLE_VALUE, it will fail anyway on WriteFile, that check is useless.

I do not insist on being perfect, if someone has better idea how to solve https://forums.openvpn.net/topic13246.html - I do not mind.

I can make git pull request from
https://github.com/chipitsine/openvpn/commit/3987bd0e035b653a5017c5eccbd54eaf22746852
if it's better.

people encounter problems on Win 8.1 (well, just couple of people here, we are running openvpn with tens of customers on Win 8.1), I beleive it is serious issue, please consider release of openvpn.

src/openvpn/console.c +0 -0
index afda8ca..3ec5758 100644
@@ -62,7 +62,6 @@ get_console_input_win32 (const char *prompt, const

bool echo, char *input, const
err = get_orig_stderr ();

Quoted 5 lines
   if (in != INVALID_HANDLE_VALUE
-      && err != INVALID_HANDLE_VALUE
       && !win32_service_interrupt (&win32_signal)
       && WriteFile (err, prompt, strlen (prompt), &len, NULL))
     {

Ilya, I am sorry to have to veto this for now.

Quoted 1 line

NAK from me, this introduces a new bug. If GetStdError() inside

if GetStdError() inside will fail, it means we do not have proper error handle. we fail in that case, no problem. what else can we do ?

Quoted 3 lines

get_orig_stderr() fails, you will end up with err == INVALID_HANDLE_VALUE here, so the check err != INVALID_HANDLE_VALUE must not be removed.

ok, if get_orig_stderr returns INVALID_HANDLE_VALUE, what is difference between

if( err != INVALID_HANDLE_VALUE && !WriteFile(err,....)

and

if(!WriteFile(err,...))

?

Quoted 3 lines

Similarly, if get_orig_stderr() returns NULL, you must not call WriteFile() either, so how about an additional "&& err != NULL" here?

if you call WriteFile with NULL handle, it will fail, the entire "if" will fail, it is not problem

Quoted 2 lines

I don't have Win 8.1 and cannot test that.

be carefull with testing.

here are tens of customers with Win 8.1, however only couple of them experience issues with "cannot read management password"
I was not able to reproduce it myself (but I eyewitness it and I confirm that initilizing "orig_stderr" variable with some proper value resolves issue)

Quoted 44 lines
Quoted 11 lines
src/openvpn/error.c +0 -1
index 6848425..acc7977 100644
@@ -454,12 +454,12 @@ close_syslog ()
 
 #ifdef WIN32
 
-static HANDLE orig_stderr;

src/openvpn/error.c close_syslog () · line 465

Quoted 10 lines
src/openvpn/error.c +2 -1
+static HANDLE orig_stderr = INVALID_HANDLE_VALUE;
 
 HANDLE
 get_orig_stderr (void)
 {
-  if (orig_stderr)
+  if (orig_stderr != INVALID_HANDLE_VALUE)
     return orig_stderr;
   else
     return GetStdHandle (STD_ERROR_HANDLE);

NAK on this, too. It exchanges one bug for another.

The STD_ERROR_HANDLE interface has, according to
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx>,
two special values, INVALID_HANDLE_VALUE (as error marker) and NULL (as marker for "we don't have a console").

I think that there needs to be a separate/new "orig_stderr_is_valid" variable, or at least the if (...) else needs to be

if (orig_stderr != NULL && orig_stderr != INVALID_HANDLE_VALUE)
...

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base. Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#5 lore raw

Re: [Openvpn-devel] NAK on uninitialized handle fix (serious issue on Win 8.1)

In reply to Matthias Andree

ok, if you think that using orig_stderr is bad idea (either NULL or INVALID_HANDLE_VALUE are special), maybe we should assign special variable which will keep an evidence whether original stderr was redirected or not and perform check against that variable ? like

BOOL stderr_was_redirected = 0;

....

if(stderr_was_redirected)
return orig_stderr;
else

    return GetStdHandle (STD_ERROR_HANDLE);

......

      /* save original stderr for password prompts */
      stderr_was_redirected = 1;
      orig_stderr = GetStdHandle (STD_ERROR_HANDLE);

2013/12/6 Matthias Andree <[email protected]...>:

Quoted 91 lines

Am 04.12.2013 14:12, schrieb Илья Шипицин:

Quoted 29 lines

Hello!

I confirm issue described here: https://forums.openvpn.net/topic13246.html
also, I confirm that it is due to random handle value (which somehow was null before Win 8.1 was released)

also, I do not understand why we should check "err" handle on INVALID_HANDLE_VALUE, it will fail anyway on WriteFile, that check is useless.

I do not insist on being perfect, if someone has better idea how to solve https://forums.openvpn.net/topic13246.html - I do not mind.

I can make git pull request from
https://github.com/chipitsine/openvpn/commit/3987bd0e035b653a5017c5eccbd54eaf22746852
if it's better.

people encounter problems on Win 8.1 (well, just couple of people here, we are running openvpn with tens of customers on Win 8.1), I beleive it is serious issue, please consider release of openvpn.

src/openvpn/console.c +0 -0
index afda8ca..3ec5758 100644
@@ -62,7 +62,6 @@ get_console_input_win32 (const char *prompt, const

bool echo, char *input, const
err = get_orig_stderr ();

Quoted 5 lines
   if (in != INVALID_HANDLE_VALUE
-      && err != INVALID_HANDLE_VALUE
       && !win32_service_interrupt (&win32_signal)
       && WriteFile (err, prompt, strlen (prompt), &len, NULL))
     {

Ilya, I am sorry to have to veto this for now.

NAK from me, this introduces a new bug. If GetStdError() inside get_orig_stderr() fails, you will end up with err == INVALID_HANDLE_VALUE here, so the check err != INVALID_HANDLE_VALUE must not be removed.

Similarly, if get_orig_stderr() returns NULL, you must not call WriteFile() either, so how about an additional "&& err != NULL" here?

I don't have Win 8.1 and cannot test that.

Quoted 10 lines
src/openvpn/error.c +0 -1
index 6848425..acc7977 100644
@@ -454,12 +454,12 @@ close_syslog ()
 
 #ifdef WIN32
 
-static HANDLE orig_stderr;

src/openvpn/error.c close_syslog () · line 465

Quoted 10 lines
src/openvpn/error.c +2 -1
+static HANDLE orig_stderr = INVALID_HANDLE_VALUE;
 
 HANDLE
 get_orig_stderr (void)
 {
-  if (orig_stderr)
+  if (orig_stderr != INVALID_HANDLE_VALUE)
     return orig_stderr;
   else
     return GetStdHandle (STD_ERROR_HANDLE);

NAK on this, too. It exchanges one bug for another.

The STD_ERROR_HANDLE interface has, according to
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx>,
two special values, INVALID_HANDLE_VALUE (as error marker) and NULL (as marker for "we don't have a console").

I think that there needs to be a separate/new "orig_stderr_is_valid" variable, or at least the if (...) else needs to be

if (orig_stderr != NULL && orig_stderr != INVALID_HANDLE_VALUE)
...

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base. Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel