From 590ad8d8ff4477ebe1c60fbaf3d7db79d9e05393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Mon, 6 Jan 2020 15:22:42 +0100 Subject: wsutil: Replace disallowed filename characters to '-' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert the removal of replacing disallowed filename characters in create_tempfile() to allow this characters in extcap interface names. This is a regression from g2925fb08. Change-Id: I833d1d19080c9c688dcaf076a840f55ef31e457d Reviewed-on: https://code.wireshark.org/review/35669 Reviewed-by: Stig Bjørlykke Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- wsutil/tempfile.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c index c744c8cf70..5082452724 100644 --- a/wsutil/tempfile.c +++ b/wsutil/tempfile.c @@ -29,8 +29,25 @@ int create_tempfile(gchar **namebuf, const char *pfx, const char *sfx, GError **err) { int fd; + gchar *safe_pfx = NULL; - gchar* filetmpl = g_strdup_printf("%sXXXXXX%s", pfx ? pfx : "", sfx ? sfx : ""); + if (pfx) { + /* The characters in "delimiters" come from: + * https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions. + * Add to the list as necessary for other OS's. + */ + const gchar *delimiters = "<>:\"/\\|?*" + "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" + "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" + "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"; + + /* Sanitize the pfx to resolve bug 7877 */ + safe_pfx = g_strdup(pfx); + safe_pfx = g_strdelimit(safe_pfx, delimiters, '-'); + } + + gchar* filetmpl = g_strdup_printf("%sXXXXXX%s", safe_pfx ? safe_pfx : "", sfx ? sfx : ""); + g_free(safe_pfx); fd = g_file_open_tmp(filetmpl, namebuf, err); -- cgit v1.2.3