diff options
author | Simon Josefsson <simon@josefsson.org> | 2005-08-15 10:10:45 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2005-08-15 10:10:45 +0000 |
commit | 672a4c1c0433e7f5fbf4ccaca17403483c06552f (patch) | |
tree | e149bd2b3e4629282d0a7b47744c7696707e1b3a /src/certtool-cfg.c | |
parent | f8fb2a3263afafa8cb39f98a41c5b161f8fbee59 (diff) | |
download | gnutls-672a4c1c0433e7f5fbf4ccaca17403483c06552f.tar.gz |
(read_int): Use readline. Use strtol, and catch out of range inputs.
Suggested by Fran.
Diffstat (limited to 'src/certtool-cfg.c')
-rw-r--r-- | src/certtool-cfg.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/certtool-cfg.c b/src/certtool-cfg.c index 434eda6be6..6fdbaa168d 100644 --- a/src/certtool-cfg.c +++ b/src/certtool-cfg.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004 Free Software Foundation + * Copyright (C) 2004, 2005 Free Software Foundation * * This file is part of GNUTLS. * @@ -29,9 +29,13 @@ #include <cfg+.h> #include <gnutls/x509.h> #include <string.h> +#include <limits.h> +#include <inttypes.h> /* Gnulib portability files. */ #include <getpass.h> +#include "error.h" +#include "readline.h" extern int batch; @@ -205,15 +209,31 @@ void read_crq_set(gnutls_x509_crq crq, const char *input_str, int read_int(const char *input_str) { - char input[128]; + char *in; + char *endptr; + long l; - fputs(input_str, stderr); - fgets(input, sizeof(input), stdin); + in = readline (input_str); - if (strlen(input) == 1) /* only newline */ - return 0; + l = strtol (in, &endptr, 0); + + if (*endptr != '\0') + { + error (0, 0, "Trailing garbage ignored: `%s'", endptr); + free (in); + return 0; + } + + if (l <= INT_MIN || l >= INT_MAX) + { + error (0, 0, "Integer out of range: `%s'", in); + free (in); + return 0; + } + + free (in); - return atoi(input); + return (int) l; } const char *read_str(const char *input_str) |