| 2163 | */ |
| 2164 | |
| 2165 | static const char * /* O - New source pointer or NULL on error */ |
| 2166 | http_copy_decode(char *dst, /* O - Destination buffer */ |
| 2167 | const char *src, /* I - Source pointer */ |
| 2168 | int dstsize, /* I - Destination size */ |
| 2169 | const char *term, /* I - Terminating characters */ |
| 2170 | int decode) /* I - Decode %-encoded values */ |
| 2171 | { |
| 2172 | char *ptr, /* Pointer into buffer */ |
| 2173 | *end; /* End of buffer */ |
| 2174 | int quoted; /* Quoted character */ |
| 2175 | |
| 2176 | |
| 2177 | /* |
| 2178 | * Copy the src to the destination until we hit a terminating character |
| 2179 | * or the end of the string. |
| 2180 | */ |
| 2181 | |
| 2182 | for (ptr = dst, end = dst + dstsize - 1; |
| 2183 | *src && (!term || !strchr(term, *src)); |
| 2184 | src ++) |
| 2185 | if (ptr < end) |
| 2186 | { |
| 2187 | if (*src == '%' && decode) |
| 2188 | { |
| 2189 | if (isxdigit(src[1] & 255) && isxdigit(src[2] & 255)) |
| 2190 | { |
| 2191 | /* |
| 2192 | * Grab a hex-encoded character... |
| 2193 | */ |
| 2194 | |
| 2195 | src ++; |
| 2196 | if (isalpha(*src)) |
| 2197 | quoted = (tolower(*src) - 'a' + 10) << 4; |
| 2198 | else |
| 2199 | quoted = (*src - '0') << 4; |
| 2200 | |
| 2201 | src ++; |
| 2202 | if (isalpha(*src)) |
| 2203 | quoted |= tolower(*src) - 'a' + 10; |
| 2204 | else |
| 2205 | quoted |= *src - '0'; |
| 2206 | |
| 2207 | *ptr++ = (char)quoted; |
| 2208 | } |
| 2209 | else |
| 2210 | { |
| 2211 | /* |
| 2212 | * Bad hex-encoded character... |
| 2213 | */ |
| 2214 | |
| 2215 | *ptr = '\0'; |
| 2216 | return (NULL); |
| 2217 | } |
| 2218 | } |
| 2219 | else if ((*src & 255) <= 0x20 || (*src & 255) >= 0x7f) |
| 2220 | { |
| 2221 | *ptr = '\0'; |
| 2222 | return (NULL); |
no outgoing calls
no test coverage detected