diff mbox series

cpio_utils: fix encryption

Message ID 20181128170331.10381-1-sbabic@denx.de
State Accepted
Headers show
Series cpio_utils: fix encryption | expand

Commit Message

Stefano Babic Nov. 28, 2018, 5:03 p.m. UTC
36c15ef3e701cc2466b0d742a00c0e6211539f1f introduced a bug when an
artifact is encrypted because the finalize() function is not called when
the input stream returns 0.

Signed-off-by: Ben Guan <ben.guan@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Signed-off-by: Stefano Babic <sbabic@denx.de>
Tested-by: Stefano Babic <sbabic@denx.de>
CC: Richard OGrady <rogrady@sbcglobal.net>
---
 core/cpio_utils.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Stefano Babic Nov. 29, 2018, 10:04 a.m. UTC | #1
Hi everybody,

On 28/11/18 18:03, Stefano Babic wrote:
> 36c15ef3e701cc2466b0d742a00c0e6211539f1f introduced a bug when an
> artifact is encrypted because the finalize() function is not called when
> the input stream returns 0.
> 
> Signed-off-by: Ben Guan <ben.guan@cn.bosch.com>
> Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
> Signed-off-by: Stefano Babic <sbabic@denx.de>
> Tested-by: Stefano Babic <sbabic@denx.de>
> CC: Richard OGrady <rogrady@sbcglobal.net>
> ---
>  core/cpio_utils.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/core/cpio_utils.c b/core/cpio_utils.c
> index 7bd812c..6216e6f 100644
> --- a/core/cpio_utils.c
> +++ b/core/cpio_utils.c
> @@ -135,10 +135,10 @@ static int input_step(void *state, void *buffer, size_t size)
>  		size = s->nbytes;
>  	}
>  	int ret = fill_buffer(s->fdin, buffer, size, s->offs, &s->checksum, s->dgst);
> -	if (ret <= 0) {
> +	if (ret < 0) {
>  		return ret;
>  	}
> -	s->nbytes -= size;
> +	s->nbytes -= ret;
>  	return ret;
>  }
>  
> @@ -173,8 +173,6 @@ static int decrypt_step(void *state, void *buffer, size_t size)
>  	ret = s->upstream_step(s->upstream_state, s->input, sizeof s->input);
>  	if (ret < 0) {
>  		return ret;
> -	} else if (ret == 0) {
> -		s->eof = true;
>  	}
>  
>  	inlen = ret;
> 

I tested with plain image, compressed image and compressed and encrypted
image - it works.

There is a new issue because a script can be compressed or encrypted,
but not both. This was not introduced by Ben's patch, I just discovered
myself by testing and should be addressed in a separate patch (or added
as limitation list in documentation). Anyway, in case of script, it is
not a big issue, and it can be fixed later.

I will apply this one to mainline.

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index 7bd812c..6216e6f 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -135,10 +135,10 @@  static int input_step(void *state, void *buffer, size_t size)
 		size = s->nbytes;
 	}
 	int ret = fill_buffer(s->fdin, buffer, size, s->offs, &s->checksum, s->dgst);
-	if (ret <= 0) {
+	if (ret < 0) {
 		return ret;
 	}
-	s->nbytes -= size;
+	s->nbytes -= ret;
 	return ret;
 }
 
@@ -173,8 +173,6 @@  static int decrypt_step(void *state, void *buffer, size_t size)
 	ret = s->upstream_step(s->upstream_state, s->input, sizeof s->input);
 	if (ret < 0) {
 		return ret;
-	} else if (ret == 0) {
-		s->eof = true;
 	}
 
 	inlen = ret;