diff options
Diffstat (limited to '')
-rw-r--r-- | networking/ftpd.c | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c index 0d6a289c7..c3125410e 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c | |||
@@ -190,54 +190,39 @@ struct globals { | |||
190 | } while (0) | 190 | } while (0) |
191 | 191 | ||
192 | 192 | ||
193 | /* escape_text("pfx:", str, (0xff << 8) + '\r') | ||
194 | * Duplicate 0xff, append \r ^^^^^^^^^^^^^^^^^^ | ||
195 | */ | ||
193 | static char * | 196 | static char * |
194 | escape_text(const char *prepend, const char *str, unsigned escapee) | 197 | escape_text(const char *prepend, const char *str, unsigned escapee) |
195 | { | 198 | { |
196 | unsigned retlen, remainlen, chunklen; | 199 | char *ret, *p; |
197 | char *ret, *found; | ||
198 | char append; | 200 | char append; |
199 | 201 | ||
200 | append = (char)escapee; | 202 | append = (char)escapee; |
201 | escapee >>= 8; | 203 | escapee >>= 8; |
202 | 204 | ||
203 | remainlen = strlen(str); | 205 | ret = xmalloc(strlen(prepend) + strlen(str) * 2 + 1 + 1); |
204 | retlen = strlen(prepend); | 206 | p = stpcpy(ret, prepend); |
205 | ret = xmalloc(retlen + remainlen * 2 + 1 + 1); | ||
206 | strcpy(ret, prepend); | ||
207 | 207 | ||
208 | for (;;) { | 208 | for (;;) { |
209 | found = strchrnul(str, escapee); | 209 | char *found = strchrnul(str, escapee); |
210 | chunklen = found - str + 1; | ||
211 | 210 | ||
212 | /* Copy chunk up to and including escapee (or NUL) to ret */ | 211 | /* Copy up to and including escapee (or NUL) */ |
213 | memcpy(ret + retlen, str, chunklen); | 212 | p = mempcpy(p, str, found - str + 1); |
214 | retlen += chunklen; | ||
215 | 213 | ||
216 | if (*found == '\0') { | 214 | if (*found == '\0') { |
217 | /* It wasn't escapee, it was NUL! */ | 215 | /* It wasn't escapee, it was NUL! */ |
218 | ret[retlen - 1] = append; /* replace NUL */ | ||
219 | ret[retlen] = '\0'; /* add NUL */ | ||
220 | break; | 216 | break; |
221 | } | 217 | } |
222 | ret[retlen++] = escapee; /* duplicate escapee */ | ||
223 | str = found + 1; | 218 | str = found + 1; |
219 | *p++ = escapee; /* duplicate escapee */ | ||
224 | } | 220 | } |
221 | p[-1] = append; /* replace NUL */ | ||
222 | *p = '\0'; /* add NUL */ | ||
225 | return ret; | 223 | return ret; |
226 | } | 224 | } |
227 | 225 | ||
228 | /* Returns strlen as a bonus */ | ||
229 | static unsigned | ||
230 | replace_char(char *str, char from, char to) | ||
231 | { | ||
232 | char *p = str; | ||
233 | while (*p) { | ||
234 | if (*p == from) | ||
235 | *p = to; | ||
236 | p++; | ||
237 | } | ||
238 | return p - str; | ||
239 | } | ||
240 | |||
241 | static void | 226 | static void |
242 | verbose_log(const char *str) | 227 | verbose_log(const char *str) |
243 | { | 228 | { |