mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: h.feurstein@gmail.com
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] commands/digest: add verify support
Date: Tue, 17 Feb 2015 08:39:27 +0100	[thread overview]
Message-ID: <20150217073927.GN12209@pengutronix.de> (raw)
In-Reply-To: <1424091755-23273-1-git-send-email-h.feurstein@gmail.com>

Hi Hubert,

On Mon, Feb 16, 2015 at 02:02:35PM +0100, h.feurstein@gmail.com wrote:
> From: Hubert Feurstein <h.feurstein@gmail.com>
> 
> Signed-off-by: Hubert Feurstein <h.feurstein@gmail.com>
> [EB]: reworked based on Sascha's comments and tested with md5sum
> Signed-off-by: Eric Bénard <eric@eukrea.com>
> ---
> -	if (argc < 2)
> -		return COMMAND_ERROR_USAGE;
> +	while ((opt = getopt(argc, argv, "v:V:")) > 0) {
> +		switch (opt) {
> +		case 'v':
> +			verify++;
> +			free(verify_hash);
> +			hash = xstrdup(optarg);
> +			len = strlen(hash);
> +			break;
> +		case 'V':
> +			verify++;
> +			free(verify_hash);
> +			hash = read_file(optarg, &bufsz);
> +			len = bufsz;
> +			break;
> +		default:
> +			ret = COMMAND_ERROR_USAGE;
> +			goto out;
> +		}
> +
> +		if (verify == 1 && (d->length * 2) <= len && hash != NULL) {
> +			min_argc += 2;
> +			verify_hash = parse_hash(d->length, hash);
> +			if (!verify_hash)
> +				return -ENOMEM;
> +			free(hash);
> +		} else
> +			return COMMAND_ERROR_USAGE;

This code in the option parsing loop looks odd. Could you just parse
options in the loop, store the hash(file) in a variable and do the
processing outside the loop?

> +	}
> +
> +	if (argc < min_argc) {
> +		ret = COMMAND_ERROR_USAGE;
> +		goto out;
> +	}
> +
> +	argv += min_argc - 2;
>  
>  	hash = calloc(d->length, sizeof(unsigned char));

xzalloc should be safe here.

>  	if (!hash) {
>  		perror("calloc");
> -		return COMMAND_ERROR_USAGE;
> +		ret = -ENOMEM;
> +		goto out;
>  	}
>  
>  	argv++;
> @@ -60,17 +133,32 @@ static int do_digest(char *algorithm, int argc, char *argv[])
>  		if (digest_file_window(d, filename, hash, start, size) < 0) {
>  			ret = 1;
>  		} else {
> -			for (i = 0; i < d->length; i++)
> +			for (i = 0; i < d->length; i++) {
>  				printf("%02x", hash[i]);
> +				if (verify > 0 && hash[i] != verify_hash[i])
> +					verify = -1;
> +			}
>  
> -			printf("  %s\t0x%08llx ... 0x%08llx\n",
> +			printf("  %s\t0x%08llx ... 0x%08llx",
>  				filename, start, start + size);
> +
> +			if (verify < 0) {
> +				printf(" ** ERROR ** ");

Printing the real hash and the expected hash would be nice here.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2015-02-17  7:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-16 13:02 h.feurstein
2015-02-17  7:39 ` Sascha Hauer [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-09-24 13:21 Eric Bénard
2014-09-25  7:15 ` Uwe Kleine-König
2013-04-19  8:43 Hubert Feurstein
2013-04-21 11:22 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150217073927.GN12209@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=h.feurstein@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox