[2/3] IPsec: Do not interpret $? as error code of move()

Message ID 20210824155048.13859-2-michael.tremer@ipfire.org
State Accepted
Commit aec1c53cf184863b06012e8ef8a747a7f3d38cde
Headers show
Series [1/3] IPsec: Fix extra whitespace in exported certificates | expand

Commit Message

Michael Tremer Aug. 24, 2021, 3:50 p.m. UTC
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 html/cgi-bin/vpnmain.cgi | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Stefan Schantl Sept. 3, 2021, 4:27 p.m. UTC | #1
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Tested-by: Stefan Schantl <stefan.schantl@ipfire.org>
> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
> ---
>  html/cgi-bin/vpnmain.cgi | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/html/cgi-bin/vpnmain.cgi b/html/cgi-bin/vpnmain.cgi
> index 980601ba0..e9064e19c 100644
> --- a/html/cgi-bin/vpnmain.cgi
> +++ b/html/cgi-bin/vpnmain.cgi
> @@ -2042,9 +2042,8 @@ END
>                         unlink ($filename);
>                         goto VPNCONF_ERROR;
>                 } else {
> -                       move($filename,
> "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
> -                       if ($? ne 0) {
> -                               $errormessage =
> "$Lang::tr{'certificate file move failed'}: $!";
> +                       unless (move($filename,
> "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem")) {
> +                               $errormessage =
> "$Lang::tr{'certificate file move failed'} ($filename): $!";
>                                 unlink ($filename);
>                                 goto VPNCONF_ERROR;
>                         }

Patch

diff --git a/html/cgi-bin/vpnmain.cgi b/html/cgi-bin/vpnmain.cgi
index 980601ba0..e9064e19c 100644
--- a/html/cgi-bin/vpnmain.cgi
+++ b/html/cgi-bin/vpnmain.cgi
@@ -2042,9 +2042,8 @@  END
 			unlink ($filename);
 			goto VPNCONF_ERROR;
 		} else {
-			move($filename, "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
-			if ($? ne 0) {
-				$errormessage = "$Lang::tr{'certificate file move failed'}: $!";
+			unless (move($filename, "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem")) {
+				$errormessage = "$Lang::tr{'certificate file move failed'} ($filename): $!";
 				unlink ($filename);
 				goto VPNCONF_ERROR;
 			}