aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2020-01-06 15:22:42 +0100
committerGuy Harris <guy@alum.mit.edu>2020-01-06 21:35:09 +0000
commit590ad8d8ff4477ebe1c60fbaf3d7db79d9e05393 (patch)
tree785eeea796dc6db1738b4254a381f3d17f0cc3b2
parent7a09c78f123b5dd1237000726f19e2801edeaf39 (diff)
wsutil: Replace disallowed filename characters to '-'
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 <stig@bjorlykke.org> Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--wsutil/tempfile.c19
1 files changed, 18 insertions, 1 deletions
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);