X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/c6940f12e2ad6ba778324f50b9a779db36238518..3ab798412da7dbfc26af43a06e92c13a7b9abf43:/cmdgen.c diff --git a/cmdgen.c b/cmdgen.c index d8d5a946..9911db15 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -119,7 +119,7 @@ void sk_cleanup(void) void showversion(void) { char *verstr = dupstr(ver); - verstr[0] = tolower(verstr[0]); + verstr[0] = tolower((unsigned char)verstr[0]); printf("PuTTYgen %s\n", verstr); sfree(verstr); } @@ -316,25 +316,47 @@ int main(int argc, char **argv) *p++ = '\0'; val = p; } else - val = NULL; + val = NULL; + if (!strcmp(opt, "-help")) { - help(); - nogo = TRUE; + if (val) { + errs = TRUE; + fprintf(stderr, "puttygen: option `-%s'" + " expects no argument\n", opt); + } else { + help(); + nogo = TRUE; + } } else if (!strcmp(opt, "-version")) { - showversion(); - nogo = TRUE; + if (val) { + errs = TRUE; + fprintf(stderr, "puttygen: option `-%s'" + " expects no argument\n", opt); + } else { + showversion(); + nogo = TRUE; + } } else if (!strcmp(opt, "-pgpfp")) { - /* support "-pgpfp" for consistency with others */ - pgp_fingerprints(); - nogo = TRUE; + if (val) { + errs = TRUE; + fprintf(stderr, "puttygen: option `-%s'" + " expects no argument\n", opt); + } else { + /* support --pgpfp for consistency */ + pgp_fingerprints(); + nogo = TRUE; + } } /* - * A sample option requiring an argument: + * For long options requiring an argument, add + * code along the lines of * * else if (!strcmp(opt, "-output")) { - * if (!val) - * errs = TRUE, error(err_optnoarg, opt); - * else + * if (!val) { + * errs = TRUE; + * fprintf(stderr, "puttygen: option `-%s'" + * " expects an argument\n", opt); + * } else * ofile = val; * } */ @@ -640,6 +662,11 @@ int main(int argc, char **argv) random_ref(); entropy = get_random_data(bits / 8); + if (!entropy) { + fprintf(stderr, "puttygen: failed to collect entropy, " + "could not generate key\n"); + return 1; + } random_add_heavynoise(entropy, bits / 8); memset(entropy, 0, bits/8); sfree(entropy);