X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/b7061c82b47bf624b916df87d7813c4fbdb48c18..b4afd23c308ed2ef7df894cfb8be532fee521ad5:/util.c diff --git a/util.c b/util.c index 8d057712..13987b9b 100644 --- a/util.c +++ b/util.c @@ -900,6 +900,30 @@ int pop_dir(char *dir) return 1; } +/** + * Return the filename, turning any newlines into '?'s. This ensures that + * outputting it on a line of its own cannot generate an empty line. This + * function can handle only 2 names at a time! + **/ +const char *safe_fname(const char *fname) +{ + static char fbuf1[MAXPATHLEN], fbuf2[MAXPATHLEN]; + static char *fbuf = fbuf2; + char *nl = strchr(fname, '\n'); + + if (!nl) + return fname; + + fbuf = fbuf == fbuf1 ? fbuf2 : fbuf1; + strlcpy(fbuf, fname, MAXPATHLEN); + nl = fbuf + (nl - (char *)fname); + do { + *nl = '?'; + } while ((nl = strchr(nl+1, '\n')) != NULL); + + return fbuf; +} + /** * Return a quoted string with the full pathname of the indicated filename. * The string " (in MODNAME)" may also be appended. The returned pointer @@ -914,6 +938,7 @@ char *full_fname(const char *fn) if (result) free(result); + fn = safe_fname(fn); if (*fn == '/') p1 = p2 = ""; else {