Index: include/base64.h =================================================================== --- /dev/null +++ include/base64.h @@ -0,0 +1,9 @@ +#include + +#define b64_ntop __b64_ntop +#define b64_pton __b64_pton + +int b64_ntop(unsigned char const *, size_t, char *, size_t); +int b64_pton(char const *, unsigned char *, size_t); + +int b64_pton_partial(char const *, unsigned char **, size_t); Index: include/resolv.h =================================================================== --- include/resolv.h +++ include/resolv.h @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -335,8 +336,6 @@ extern const struct res_sym __p_rcode_syms[]; #endif /* SHARED_LIBBIND */ -#define b64_ntop __b64_ntop -#define b64_pton __b64_pton #define dn_comp __dn_comp #define dn_count_labels __dn_count_labels #define dn_expand __dn_expand @@ -420,8 +419,6 @@ int sym_ston(const struct res_sym *, const char *, int *); const char * sym_ntos(const struct res_sym *, int, int *); const char * sym_ntop(const struct res_sym *, int, int *); -int b64_ntop(u_char const *, size_t, char *, size_t); -int b64_pton(char const *, u_char *, size_t); int loc_aton(const char *, u_char *); const char * loc_ntoa(const u_char *, char *); int dn_skipname(const u_char *, const u_char *); Index: lib/libc/net/Symbol.map =================================================================== --- lib/libc/net/Symbol.map +++ lib/libc/net/Symbol.map @@ -5,6 +5,7 @@ FBSD_1.0 { __b64_ntop; __b64_pton; + b64_pton_partial; ether_line; ether_aton; ether_aton_r; Index: lib/libc/net/base64.c =================================================================== --- lib/libc/net/base64.c +++ lib/libc/net/base64.c @@ -43,15 +43,8 @@ #include __FBSDID("$FreeBSD$"); -#include -#include - -#include -#include -#include - #include -#include +#include #include #include #include @@ -192,14 +185,18 @@ */ int -b64_pton(const char *src, u_char *target, size_t targsize) +b64_pton_partial(const char *src, unsigned char **target, size_t targsize) { - int tarindex, state, ch; + int state, ch; u_char nextbyte; char *pos; + unsigned char *tarend, *orig; state = 0; - tarindex = 0; + if (*target) { + tarend = *target + targsize; + orig = *target; + } while ((ch = *src++) != '\0') { if (isspace((unsigned char)ch)) /* Skip whitespace anywhere. */ @@ -214,48 +211,48 @@ switch (state) { case 0: - if (target) { - if ((size_t)tarindex >= targsize) + if (*target) { + if (*target >= tarend) return (-1); - target[tarindex] = (pos - Base64) << 2; + **target = (pos - Base64) << 2; } state = 1; break; case 1: - if (target) { - if ((size_t)tarindex >= targsize) + if (*target) { + if (*target >= tarend) return (-1); - target[tarindex] |= (pos - Base64) >> 4; + **target |= (pos - Base64) >> 4; nextbyte = ((pos - Base64) & 0x0f) << 4; - if ((size_t)tarindex + 1 < targsize) - target[tarindex + 1] = nextbyte; + if (*target + 1 < tarend) + (*target)[1] = nextbyte; else if (nextbyte) return (-1); } - tarindex++; + (*target)++; state = 2; break; case 2: - if (target) { - if ((size_t)tarindex >= targsize) + if (*target) { + if (*target >= tarend) return (-1); - target[tarindex] |= (pos - Base64) >> 2; + **target |= (pos - Base64) >> 2; nextbyte = ((pos - Base64) & 0x03) << 6; - if ((size_t)tarindex + 1 < targsize) - target[tarindex + 1] = nextbyte; + if (*target + 1 < tarend) + (*target)[1] = nextbyte; else if (nextbyte) return (-1); } - tarindex++; + (*target)++; state = 3; break; case 3: - if (target) { - if ((size_t)tarindex >= targsize) + if (*target) { + if (*target >= tarend) return (-1); - target[tarindex] |= (pos - Base64); + **target |= (pos - Base64); } - tarindex++; + (*target)++; state = 0; break; default: @@ -302,8 +299,7 @@ * zeros. If we don't check them, they become a * subliminal channel. */ - if (target && (size_t)tarindex < targsize && - target[tarindex] != 0) + if (*target && *target < tarend && **target != 0) return (-1); } } else { @@ -315,5 +311,11 @@ return (-1); } - return (tarindex); + return (*target - orig); +} + +int +b64_pton(const char *src, unsigned char *target, size_t targsize) +{ + return b64_pton_partial(src, &target, targsize); }