[Help-gnutls] Re: Really I can not understand nothing of SSL... For the moment to avoid confusion...
Simon Josefsson
jas at extundo.com
Mon Aug 15 12:17:43 CEST 2005
Fran <e_agf at yahoo.es> writes:
>> > I suggest this modifications for certtoll-cfg.c function read_int(), for
>> > the moment:
>> > Something like this:
>> > Line 32:
>> >> #include <limits.h>
>> > Line 224:
>> >> if (atoll (input) > INT_MAX) /*Could be other condition*/
>> >> {
>> >> fprintf (stderr, "Sorry certtool still not support numbers larger that: %u\n", INT_MAX);
>> >> return 0;
>> >> };
>>
>> atoll isn't available on C89 platforms..
>
> Right, atoi (obsolete) , and atoll (C99 and obsolete),but "something
> like" this is not "this".
> What about this?
It looked rather unreadable to me. I installed the following instead.
As a bonus, you get line editing capabilities if you have libreadline
installed, and it will accept non-decimal input too.
Index: src/certtool-cfg.c
===================================================================
RCS file: /cvs/gnutls/gnutls/src/certtool-cfg.c,v
retrieving revision 2.11
diff -u -p -r2.11 certtool-cfg.c
--- src/certtool-cfg.c 26 May 2005 15:27:30 -0000 2.11
+++ src/certtool-cfg.c 15 Aug 2005 10:08:10 -0000
@@ -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, c
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)
More information about the Gnutls-help
mailing list