Simple Directmedia Layer
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix possible bug with Windows dialogs

The Windows implementation of dialogs use the Win32 API, which expects the file filters to have null bytes as separator, and two null bytes at the end of the filter list. To help with string manipulation, the internal code uses 0x01 bytes instead of null bytes, and converts all 0x01 bytes into null bytes at the last moment. If someone decides to put two consecutive 0x01 bytes in their filter names, the code might mistakenly pick them up and convert them to null bytes, leading to Windows failing to pick up later filters. In practice, this is probably not so bad, since it requires someone to have control over file filters already, and allows at most ignoring the following file filters. It is also unlikely to happen by accident since 0x01 is not printable. This commit fixes that by replacing all the 0x01 bytes with the space character.

authored by

Semphris and committed by
Sam Lantinga
684098fa bc9c86bc

+19 -1
+19 -1
src/dialog/windows/SDL_windowsdialog.c
··· 63 63 return as_reported_by_windows - 1; 64 64 } 65 65 66 + char *clear_filt_names(const char *filt) 67 + { 68 + char *cleared = SDL_strdup(filt); 69 + 70 + for (char *c = cleared; *c; c++) { 71 + /* 0x01 bytes are used as temporary replacement for the various 0x00 72 + bytes required by Win32 (one null byte between each filter, two at 73 + the end of the filters). Filter out these bytes from the filter names 74 + to avoid early-ending the filters if someone puts two consecutive 75 + 0x01 bytes in their filter names. */ 76 + if (*c == '\x01') { 77 + *c = ' '; 78 + } 79 + } 80 + 81 + return cleared; 82 + } 83 + 66 84 // TODO: The new version of file dialogs 67 85 void windows_ShowFileDialog(void *ptr) 68 86 { ··· 161 179 if (filters) { 162 180 // '\x01' is used in place of a null byte 163 181 // suffix needs two null bytes in case the filter list is empty 164 - char *filterlist = convert_filters(filters, nfilters, NULL, "", "", 182 + char *filterlist = convert_filters(filters, nfilters, clear_filt_names, "", "", 165 183 "\x01\x01", "", "\x01", "\x01", 166 184 "*.", ";*.", ""); 167 185