replace sprintf all over the place

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1635 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1997-05-02 14:29:33 +00:00
parent 1495f52771
commit dd02a92a8b
55 changed files with 831 additions and 471 deletions

View File

@@ -80,10 +80,10 @@ typedef struct {
} OtpContext;
OtpAlgorithm *otp_find_alg (char *name);
void otp_print_stddict (OtpKey key, char *str);
void otp_print_hex (OtpKey key, char *str);
void otp_print_stddict_extended (OtpKey key, char *str);
void otp_print_hex_extended (OtpKey key, char *str);
void otp_print_stddict (OtpKey key, char *str, size_t sz);
void otp_print_hex (OtpKey key, char *str, size_t sz);
void otp_print_stddict_extended (OtpKey key, char *str, size_t sz);
void otp_print_hex_extended (OtpKey key, char *str, size_t sz);
unsigned otp_checksum (OtpKey key);
int otp_parse_hex (OtpKey key, char *);
int otp_parse_stddict (OtpKey key, char *);

View File

@@ -65,7 +65,9 @@ otp_challenge (OtpContext *ctx, char *user, char *str, size_t len)
otp_db_close (dbm);
if (ret)
return ret;
sprintf (str, "[ otp-%s %u %s ]", ctx->alg->name, ctx->n-1, ctx->seed);
snprintf (str, len,
"[ otp-%s %u %s ]",
ctx->alg->name, ctx->n-1, ctx->seed);
ctx->challengep = 1;
return 0;
}

View File

@@ -2183,7 +2183,7 @@ parse_words(unsigned wn[],
return 0;
}
static
static int
otp_parse_internal (OtpKey key, char *str, OtpAlgorithm *alg,
int (*convert)(char *, void *))
{

View File

@@ -303,18 +303,6 @@ static char *std_dict[] =
"YARD", "YARN", "YAWL", "YAWN", "YEAH", "YEAR", "YELL", "YOGA",
"YOKE" };
static char *
add_word (char *s, unsigned n)
{
char *w;
w = std_dict[n];
strcpy (s, w);
s += strlen(w);
*s++ = ' ';
return s;
}
unsigned
otp_checksum (OtpKey key)
{
@@ -331,38 +319,42 @@ otp_checksum (OtpKey key)
}
void
otp_print_stddict (OtpKey key, char *str)
otp_print_stddict (OtpKey key, char *str, size_t sz)
{
unsigned sum;
sum = otp_checksum (key);
str = add_word (str, (key[0] << 3) | (key[1] >> 5));
str = add_word (str, ((key[1] & 0x1F) << 6) | (key[2] >> 2));
str = add_word (str, ((key[2] & 0x03) << 9) | (key[3] << 1) | (key[4] >> 7));
str = add_word (str, ((key[4] & 0x7F) << 4) | (key[5] >> 4));
str = add_word (str, ((key[5] & 0x0F) << 7) | (key[6] >> 1));
str = add_word (str, ((key[6] & 0x01) << 10) | (key[7] << 2) | sum);
*--str = '\0';
snprintf (str, sz,
"%s %s %s %s %s %s",
std_dict[(key[0] << 3) | (key[1] >> 5)],
std_dict[((key[1] & 0x1F) << 6) | (key[2] >> 2)],
std_dict[((key[2] & 0x03) << 9) | (key[3] << 1) | (key[4] >> 7)],
std_dict[((key[4] & 0x7F) << 4) | (key[5] >> 4)],
std_dict[((key[5] & 0x0F) << 7) | (key[6] >> 1)],
std_dict[((key[6] & 0x01) << 10) | (key[7] << 2) | sum]);
}
void
otp_print_hex (OtpKey key, char *str)
otp_print_hex (OtpKey key, char *str, size_t sz)
{
sprintf (str, "%02x%02x%02x%02x%02x%02x%02x%02x",
key[0], key[1], key[2], key[3],
key[4], key[5], key[6], key[7]);
snprintf (str, sz,
"%02x%02x%02x%02x%02x%02x%02x%02x",
key[0], key[1], key[2], key[3],
key[4], key[5], key[6], key[7]);
}
void
otp_print_hex_extended (OtpKey key, char *str)
otp_print_hex_extended (OtpKey key, char *str, size_t sz)
{
strcpy (str, OTP_HEXPREFIX);
otp_print_hex (key, str + strlen(OTP_HEXPREFIX));
strncpy (str, OTP_HEXPREFIX, sz);
str[sz-1] = '\0';
otp_print_hex (key, str + strlen(OTP_HEXPREFIX), sz - strlen(OTP_HEXPREFIX));
}
void
otp_print_stddict_extended (OtpKey key, char *str)
otp_print_stddict_extended (OtpKey key, char *str, size_t sz)
{
strcpy (str, OTP_WORDPREFIX);
otp_print_stddict (key, str + strlen(OTP_WORDPREFIX));
strncpy (str, OTP_WORDPREFIX, sz);
str[sz-1] = '\0';
otp_print_stddict (key, str + strlen(OTP_WORDPREFIX), sz - strlen(OTP_WORDPREFIX));
}

View File

@@ -46,13 +46,14 @@ RCSID("$Id$");
#include <otp.h>
static int
test_one(OtpKey key1, char *name, char *val, void (*print)(OtpKey,char*),
test_one(OtpKey key1, char *name, char *val,
void (*print)(OtpKey,char*, size_t),
OtpAlgorithm *alg)
{
char buf[256];
OtpKey key2;
(*print)(key1, buf);
(*print)(key1, buf, sizeof(buf));
printf ("%s: %s, ", name, buf);
if (strcmp (buf, val) != 0) {
printf ("failed(*%s* != *%s*)\n", buf, val);