summaryrefslogtreecommitdiff
path: root/common/print.c
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2016-09-20 11:48:21 -0400
committerThomas Markwalder <tmark@isc.org>2016-09-20 11:48:21 -0400
commit5534984b29aa1e9c789ab337c4598981448f7dfd (patch)
tree91b933d6e596fd0b5c7e1e4f2dc165621bc9a460 /common/print.c
parente675b663590ffee8d300694be80effc4e1447094 (diff)
downloadisc-dhcp-5534984b29aa1e9c789ab337c4598981448f7dfd.tar.gz
[master] Fixed sporadic server crash when lease-id-format is hex
Merges in rt43185.
Diffstat (limited to 'common/print.c')
-rw-r--r--common/print.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/common/print.c b/common/print.c
index a694fedd..ce368c4d 100644
--- a/common/print.c
+++ b/common/print.c
@@ -383,15 +383,27 @@ void print_hex_only (len, data, limit, buf)
unsigned limit;
char *buf;
{
- unsigned i;
+ char *bufptr = buf;
+ int byte = 0;
- if ((buf == NULL) || (limit < 3))
+ if (data == NULL || bufptr == NULL || limit == 0) {
return;
+ }
- for (i = 0; (i < limit / 3) && (i < len); i++) {
- sprintf(&buf[i*3], "%02x:", data[i]);
+ if (((len == 0) || ((len * 3) > limit))) {
+ *bufptr = 0x0;
+ return;
}
- buf[(i * 3) - 1] = 0;
+
+ for ( ; byte < len; ++byte) {
+ if (byte > 0) {
+ *bufptr++ = ':';
+ }
+
+ sprintf(bufptr, "%02x", data[byte]);
+ bufptr += 2;
+ }
+
return;
}