Commit bea6403
committed
Use byte-level widening/narrowing on Linux SQLWCHAR paths
Follow-up to the ConvertingString discussion in #289. The 8-byte floor in
Alloc() introduced by the previous commit was a crutch: it avoided the
strcpy heap overflow for the SQL-state case but left the destructor's
mbstowcs((wchar_t*)unicodeString, ..., lengthString) writing 4-byte
wchar_t units into a caller buffer that is SQLWCHAR-sized (2 bytes).
Even when that did not overflow, the data was wrong — 'HY000' became
'H' after the client reinterpreted the bytes as UCS-2.
Replace the Linux non-connection paths in both directions with the same
byte-widening / byte-narrowing loop that unixODBC itself uses internally
(ansi_to_unicode_copy / unicode_to_ansi_copy). This is correct for the
ASCII-only error/state strings that reach this code; non-ASCII handling
remains the subject of the broader rewrite tracked as Tier 9.1 in #287.
Changes in MainUnicode.cpp:
- lengthString now uses sizeof(SQLWCHAR) again (correct SQLWCHAR count).
- Destructor Linux branch widens bytes into SQLWCHAR units.
- convUnicodeToString Linux branch narrows SQLWCHAR to low bytes.
- Temporary NUL is written as a SQLWCHAR-sized zero (not wchar_t).
- Remove the Alloc() floor — no longer needed.
- Add sqlwcharLen() helper; wcslen() on SQLWCHAR data is unsafe on Linux.1 parent 0f8f90f commit bea6403
1 file changed
Lines changed: 61 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
41 | 56 | | |
42 | 57 | | |
43 | 58 | | |
| |||
85 | 100 | | |
86 | 101 | | |
87 | 102 | | |
88 | | - | |
| 103 | + | |
89 | 104 | | |
90 | 105 | | |
91 | 106 | | |
| |||
135 | 150 | | |
136 | 151 | | |
137 | 152 | | |
138 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
139 | 171 | | |
140 | 172 | | |
141 | 173 | | |
142 | 174 | | |
143 | 175 | | |
144 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
145 | 180 | | |
146 | 181 | | |
147 | 182 | | |
| |||
170 | 205 | | |
171 | 206 | | |
172 | 207 | | |
| 208 | + | |
173 | 209 | | |
174 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
175 | 214 | | |
176 | 215 | | |
177 | 216 | | |
178 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
179 | 220 | | |
180 | 221 | | |
181 | 222 | | |
| |||
185 | 226 | | |
186 | 227 | | |
187 | 228 | | |
188 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
189 | 233 | | |
190 | 234 | | |
191 | 235 | | |
| |||
198 | 242 | | |
199 | 243 | | |
200 | 244 | | |
201 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
202 | 254 | | |
203 | 255 | | |
204 | 256 | | |
| |||
219 | 271 | | |
220 | 272 | | |
221 | 273 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
| 274 | + | |
| 275 | + | |
232 | 276 | | |
233 | 277 | | |
234 | 278 | | |
| |||
0 commit comments