mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-10-24 14:48:16 -04:00
Added safe_fname() that converts any newlines in a name into '?'s.
This commit is contained in:
1 parent
3cb22c204c
commit
820b6c9aa0
1 file changed
+21
@@ -900,6 +900,27 @@ 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.
|
||||
**/
|
||||
const char *safe_fname(const char *fname)
|
||||
{
|
||||
static char fbuf[MAXPATHLEN];
|
||||
char *nl = strchr(fname, '\n');
|
||||
|
||||
if (!nl)
|
||||
return fname;
|
||||
|
||||
strlcpy(fbuf, fname, sizeof fbuf);
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user