diff options
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index d320c1816a7b..33bed5e67a21 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -671,7 +671,7 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | |||
671 | return p; | 671 | return p; |
672 | } | 672 | } |
673 | 673 | ||
674 | static char *ip6_compressed_string(char *p, const struct in6_addr *addr) | 674 | static char *ip6_compressed_string(char *p, const char *addr) |
675 | { | 675 | { |
676 | int i; | 676 | int i; |
677 | int j; | 677 | int j; |
@@ -683,7 +683,12 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr) | |||
683 | u8 hi; | 683 | u8 hi; |
684 | u8 lo; | 684 | u8 lo; |
685 | bool needcolon = false; | 685 | bool needcolon = false; |
686 | bool useIPv4 = ipv6_addr_v4mapped(addr) || ipv6_addr_is_isatap(addr); | 686 | bool useIPv4; |
687 | struct in6_addr in6; | ||
688 | |||
689 | memcpy(&in6, addr, sizeof(struct in6_addr)); | ||
690 | |||
691 | useIPv4 = ipv6_addr_v4mapped(&in6) || ipv6_addr_is_isatap(&in6); | ||
687 | 692 | ||
688 | memset(zerolength, 0, sizeof(zerolength)); | 693 | memset(zerolength, 0, sizeof(zerolength)); |
689 | 694 | ||
@@ -695,7 +700,7 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr) | |||
695 | /* find position of longest 0 run */ | 700 | /* find position of longest 0 run */ |
696 | for (i = 0; i < range; i++) { | 701 | for (i = 0; i < range; i++) { |
697 | for (j = i; j < range; j++) { | 702 | for (j = i; j < range; j++) { |
698 | if (addr->s6_addr16[j] != 0) | 703 | if (in6.s6_addr16[j] != 0) |
699 | break; | 704 | break; |
700 | zerolength[i]++; | 705 | zerolength[i]++; |
701 | } | 706 | } |
@@ -722,7 +727,7 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr) | |||
722 | needcolon = false; | 727 | needcolon = false; |
723 | } | 728 | } |
724 | /* hex u16 without leading 0s */ | 729 | /* hex u16 without leading 0s */ |
725 | word = ntohs(addr->s6_addr16[i]); | 730 | word = ntohs(in6.s6_addr16[i]); |
726 | hi = word >> 8; | 731 | hi = word >> 8; |
727 | lo = word & 0xff; | 732 | lo = word & 0xff; |
728 | if (hi) { | 733 | if (hi) { |
@@ -741,19 +746,19 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr) | |||
741 | if (useIPv4) { | 746 | if (useIPv4) { |
742 | if (needcolon) | 747 | if (needcolon) |
743 | *p++ = ':'; | 748 | *p++ = ':'; |
744 | p = ip4_string(p, &addr->s6_addr[12], false); | 749 | p = ip4_string(p, &in6.s6_addr[12], false); |
745 | } | 750 | } |
746 | 751 | ||
747 | *p = '\0'; | 752 | *p = '\0'; |
748 | return p; | 753 | return p; |
749 | } | 754 | } |
750 | 755 | ||
751 | static char *ip6_string(char *p, const struct in6_addr *addr, const char *fmt) | 756 | static char *ip6_string(char *p, const char *addr, const char *fmt) |
752 | { | 757 | { |
753 | int i; | 758 | int i; |
754 | for (i = 0; i < 8; i++) { | 759 | for (i = 0; i < 8; i++) { |
755 | p = pack_hex_byte(p, addr->s6_addr[2 * i]); | 760 | p = pack_hex_byte(p, *addr++); |
756 | p = pack_hex_byte(p, addr->s6_addr[2 * i + 1]); | 761 | p = pack_hex_byte(p, *addr++); |
757 | if (fmt[0] == 'I' && i != 7) | 762 | if (fmt[0] == 'I' && i != 7) |
758 | *p++ = ':'; | 763 | *p++ = ':'; |
759 | } | 764 | } |
@@ -768,9 +773,9 @@ static char *ip6_addr_string(char *buf, char *end, const u8 *addr, | |||
768 | char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; | 773 | char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; |
769 | 774 | ||
770 | if (fmt[0] == 'I' && fmt[2] == 'c') | 775 | if (fmt[0] == 'I' && fmt[2] == 'c') |
771 | ip6_compressed_string(ip6_addr, (const struct in6_addr *)addr); | 776 | ip6_compressed_string(ip6_addr, addr); |
772 | else | 777 | else |
773 | ip6_string(ip6_addr, (const struct in6_addr *)addr, fmt); | 778 | ip6_string(ip6_addr, addr, fmt); |
774 | 779 | ||
775 | return string(buf, end, ip6_addr, spec); | 780 | return string(buf, end, ip6_addr, spec); |
776 | } | 781 | } |
@@ -1092,13 +1097,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1092 | 1097 | ||
1093 | /* Reject out-of-range values early. Large positive sizes are | 1098 | /* Reject out-of-range values early. Large positive sizes are |
1094 | used for unknown buffer sizes. */ | 1099 | used for unknown buffer sizes. */ |
1095 | if (unlikely((int) size < 0)) { | 1100 | if (WARN_ON_ONCE((int) size < 0)) |
1096 | /* There can be only one.. */ | ||
1097 | static char warn = 1; | ||
1098 | WARN_ON(warn); | ||
1099 | warn = 0; | ||
1100 | return 0; | 1101 | return 0; |
1101 | } | ||
1102 | 1102 | ||
1103 | str = buf; | 1103 | str = buf; |
1104 | end = buf + size; | 1104 | end = buf + size; |
@@ -1544,13 +1544,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1544 | 1544 | ||
1545 | struct printf_spec spec = {0}; | 1545 | struct printf_spec spec = {0}; |
1546 | 1546 | ||
1547 | if (unlikely((int) size < 0)) { | 1547 | if (WARN_ON_ONCE((int) size < 0)) |
1548 | /* There can be only one.. */ | ||
1549 | static char warn = 1; | ||
1550 | WARN_ON(warn); | ||
1551 | warn = 0; | ||
1552 | return 0; | 1548 | return 0; |
1553 | } | ||
1554 | 1549 | ||
1555 | str = buf; | 1550 | str = buf; |
1556 | end = buf + size; | 1551 | end = buf + size; |
@@ -1776,7 +1771,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1776 | * advance both strings to next white space | 1771 | * advance both strings to next white space |
1777 | */ | 1772 | */ |
1778 | if (*fmt == '*') { | 1773 | if (*fmt == '*') { |
1779 | while (!isspace(*fmt) && *fmt) | 1774 | while (!isspace(*fmt) && *fmt != '%' && *fmt) |
1780 | fmt++; | 1775 | fmt++; |
1781 | while (!isspace(*str) && *str) | 1776 | while (!isspace(*str) && *str) |
1782 | str++; | 1777 | str++; |