diff mbox series

px5g-mbedtls error check

Message ID 7951e3e1-49b2-7756-bce7-468adfa85c78@chocky.org
State Not Applicable
Delegated to: Petr Štetiar
Headers show
Series px5g-mbedtls error check | expand

Commit Message

Peter Naulls Dec. 5, 2022, 7:03 p.m. UTC
In 22.03, px5-mbedtls isn't bothering to check if the output was opened:

  }

Comments

Daniel Golle Dec. 5, 2022, 9:27 p.m. UTC | #1
Hi Peter,

thank you for pointing this out and submitting a patch.

On Mon, Dec 05, 2022 at 02:03:48PM -0500, Peter Naulls wrote:
> 
> 
> In 22.03, px5-mbedtls isn't bothering to check if the output was opened:

You patch lacks a Signed-off-by: line in the end of the patch
description.

> 
> --- a/package/utils/px5g-mbedtls/px5g-mbedtls.c
> +++ b/package/utils/px5g-mbedtls/px5g-mbedtls.c
> @@ -29,6 +29,7 @@
>  #include <unistd.h>
>  #include <fcntl.h>
>  #include <stdbool.h>
> +#include <errno.h>
> 
>  #include <mbedtls/bignum.h>
>  #include <mbedtls/x509_crt.h>
> @@ -70,6 +71,11 @@ static void write_file(const char *path, int len, bool pem)
>         if (path)
>                 f = fopen(path, "w");
> 
> +    if (!f) {
> +               fprintf(stderr, "Failed to open output '%s': %s\n", path,
> strerror(errno));
> +               exit(1);
> +    }
> +
>         fwrite(buf_start, 1, len, f);
>         fclose(f);
>  }

Unfortunately your mail user agent has mangled the tabs into 4 spaces
which results in the patch no longer applying:

warning: Patch sent with format=flowed; space at the end of lines might be lost.
Applying: px5g-mbedtls error check
error: patch failed: package/utils/px5g-mbedtls/px5g-mbedtls.c:70
error: package/utils/px5g-mbedtls/px5g-mbedtls.c: patch does not apply
Patch failed at 0001 px5g-mbedtls error check
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
...
To avoid problems like that, please use 'git send-email' or at least
'git format-patch' to submit the patch. If using a specific graphical
or web mail user agent cannot be avoided at all, as a last resort it is
also ok to send patches generated using 'git format-patch' as an
attachment.


To be consistent in style it would also be better to change the patch
subject to "px5g-mbedtls: add error check" or something like that.


Cheers


Daniel
diff mbox series

Patch

--- a/package/utils/px5g-mbedtls/px5g-mbedtls.c
+++ b/package/utils/px5g-mbedtls/px5g-mbedtls.c
@@ -29,6 +29,7 @@ 
  #include <unistd.h>
  #include <fcntl.h>
  #include <stdbool.h>
+#include <errno.h>

  #include <mbedtls/bignum.h>
  #include <mbedtls/x509_crt.h>
@@ -70,6 +71,11 @@  static void write_file(const char *path, int len, bool pem)
         if (path)
                 f = fopen(path, "w");

+    if (!f) {
+               fprintf(stderr, "Failed to open output '%s': %s\n", path, 
strerror(errno));
+               exit(1);
+    }
+
         fwrite(buf_start, 1, len, f);
         fclose(f);