mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-14 09:37:34 -05:00
Sanitise bad characters in log file names.
On Windows, colons are illegal in filenames, because they're part of the path syntax. But colons can appear in automatically constructed log file names, if an IPv6 address is expanded from the &H placeholder. Now we coerce any such illegal characters to '.', which is a bit of a bodge but should at least cause a log file to be generated.
This commit is contained in:
15
logging.c
15
logging.c
@ -446,6 +446,7 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port,
|
||||
s = filename_to_str(src);
|
||||
|
||||
while (*s) {
|
||||
int sanitise = FALSE;
|
||||
/* Let (bufp, len) be the string to append. */
|
||||
bufp = buf; /* don't usually override this */
|
||||
if (*s == '&') {
|
||||
@ -478,6 +479,12 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port,
|
||||
if (c != '&')
|
||||
buf[size++] = c;
|
||||
}
|
||||
/* Never allow path separators - or any other illegal
|
||||
* filename character - to come out of any of these
|
||||
* auto-format directives. E.g. 'hostname' can contain
|
||||
* colons, if it's an IPv6 address, and colons aren't
|
||||
* legal in filenames on Windows. */
|
||||
sanitise = TRUE;
|
||||
} else {
|
||||
buf[0] = *s++;
|
||||
size = 1;
|
||||
@ -486,8 +493,12 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port,
|
||||
bufsize = (buflen + size) * 5 / 4 + 512;
|
||||
buffer = sresize(buffer, bufsize, char);
|
||||
}
|
||||
memcpy(buffer + buflen, bufp, size);
|
||||
buflen += size;
|
||||
while (size-- > 0) {
|
||||
char c = *bufp++;
|
||||
if (sanitise)
|
||||
c = filename_char_sanitise(c);
|
||||
buffer[buflen++] = c;
|
||||
}
|
||||
}
|
||||
buffer[buflen] = '\0';
|
||||
|
||||
|
Reference in New Issue
Block a user