Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libresolv PR/50907: David Binderman: Remove useless strl...
details: https://anonhg.NetBSD.org/src/rev/5b43606e4e7b
branches: trunk
changeset: 343967:5b43606e4e7b
user: christos <christos%NetBSD.org@localhost>
date: Mon Mar 07 14:35:39 2016 +0000
description:
PR/50907: David Binderman: Remove useless strlen()'s and memcpy()'s.
diffstat:
lib/libresolv/hmac_link.c | 62 +++++++++++++++++++++++-----------------------
1 files changed, 31 insertions(+), 31 deletions(-)
diffs (96 lines):
diff -r 7fb365b60bd6 -r 5b43606e4e7b lib/libresolv/hmac_link.c
--- a/lib/libresolv/hmac_link.c Mon Mar 07 14:35:21 2016 +0000
+++ b/lib/libresolv/hmac_link.c Mon Mar 07 14:35:39 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hmac_link.c,v 1.2 2012/11/16 02:16:38 christos Exp $ */
+/* $NetBSD: hmac_link.c,v 1.3 2016/03/07 14:35:39 christos Exp $ */
/*
* Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
@@ -20,7 +20,7 @@
#if 0
static const char rcsid[] = "Header: /proj/cvs/prod/libbind/dst/hmac_link.c,v 1.8 2007/09/24 17:18:25 each Exp ";
#else
-__RCSID("$NetBSD: hmac_link.c,v 1.2 2012/11/16 02:16:38 christos Exp $");
+__RCSID("$NetBSD: hmac_link.c,v 1.3 2016/03/07 14:35:39 christos Exp $");
#endif
/*%
@@ -268,48 +268,48 @@
const int buff_len)
{
char *bp;
- int len, i, key_len;
+#define BUF_LEFT (size_t)(buff_len - (bp - buff))
+ int len, key_len;
u_char key[HMAC_LEN];
HMAC_Key *hkey;
+ static const char keystr[] = "Key: ";
+
+ if (buff == NULL)
+ return -1; /*%< no output area */
if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (0);
- /*
- * Using snprintf() would be so much simpler here.
- */
- if (buff == NULL ||
- buff_len <= (int)(strlen(KEY_FILE_FMT_STR) +
- strlen(KEY_FILE_FORMAT) + 4))
- return (-1); /*%< no OR not enough space in output area */
+ return 0;
+
+ /* write file header */
hkey = (HMAC_Key *) dkey->dk_KEY_struct;
- memset(buff, 0, buff_len); /*%< just in case */
- /* write file header */
- snprintf(buff, buff_len, KEY_FILE_FMT_STR, KEY_FILE_FORMAT,
+ len = snprintf(buff, buff_len, KEY_FILE_FMT_STR, KEY_FILE_FORMAT,
KEY_HMAC_MD5, "HMAC");
+ if (len < 0 || len >= buff_len)
+ return -1; /*%< not enough space in output area */
+ bp = buff + len;
+ if (BUF_LEFT < sizeof(keystr))
+ return -1;
- bp = buff + strlen(buff);
+ memcpy(bp, keystr, sizeof(keystr) - 1);
+ bp += sizeof(keystr) - 1;
- memset(key, 0, HMAC_LEN);
- for (i = 0; i < HMAC_LEN; i++)
- key[i] = hkey->hk_ipad[i] ^ HMAC_IPAD;
- for (i = HMAC_LEN - 1; i >= 0; i--)
- if (key[i] != 0)
+ for (key_len = 0; key_len < HMAC_LEN; key_len++)
+ key[key_len] = hkey->hk_ipad[key_len] ^ HMAC_IPAD;
+ for (key_len = HMAC_LEN - 1; key_len >= 0; key_len--)
+ if (key[key_len] != 0)
break;
- key_len = i + 1;
+ key_len++;
- if (buff_len - (bp - buff) < 6)
- return (-1);
- strcat(bp, "Key: ");
- bp += strlen("Key: ");
-
- len = b64_ntop(key, key_len, bp, (size_t)(buff_len - (bp - buff)));
+ len = b64_ntop(key, key_len, bp, BUF_LEFT);
if (len < 0)
- return (-1);
+ return -1;
bp += len;
- if (buff_len - (bp - buff) < 2)
- return (-1);
+
+ if (BUF_LEFT < 2)
+ return -1;
*(bp++) = '\n';
- *bp = '\0';
+
+ memset(bp, 0, BUF_LEFT);
return (int)(bp - buff);
}
Home |
Main Index |
Thread Index |
Old Index