Changeset 55955 in vbox
- Timestamp:
- May 20, 2015 12:07:06 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/shflsvc.h
r53624 r55955 222 222 DECLINLINE(bool) ShflStringIsValidOut(PCSHFLSTRING pString, uint32_t cbBuf) 223 223 { 224 if (RT_UNLIKELY(cbBuf <= RT_UOFFSETOF(SHFLSTRING, String))) 225 return false; 226 if (RT_UNLIKELY((uint32_t)pString->u16Size + RT_UOFFSETOF(SHFLSTRING, String) > cbBuf)) 227 return false; 228 if (RT_UNLIKELY(pString->u16Length >= pString->u16Size)) 229 return false; 230 return true; 224 if (RT_LIKELY(cbBuf > RT_UOFFSETOF(SHFLSTRING, String))) 225 if (RT_LIKELY((uint32_t)pString->u16Size + RT_UOFFSETOF(SHFLSTRING, String) <= cbBuf)) 226 if (RT_LIKELY(pString->u16Length < pString->u16Size)) 227 return true; 228 return false; 231 229 } 232 230 … … 243 241 { 244 242 int rc; 245 if (RT_UNLIKELY(cbBuf <= RT_UOFFSETOF(SHFLSTRING, String))) 246 return false; 247 if (RT_UNLIKELY((uint32_t)pString->u16Size + RT_UOFFSETOF(SHFLSTRING, String) > cbBuf)) 248 return false; 249 if (fUtf8Not16) 243 if (RT_LIKELY(cbBuf > RT_UOFFSETOF(SHFLSTRING, String))) 250 244 { 251 /* UTF-8: */ 252 if (RT_UNLIKELY(pString->u16Length >= pString->u16Size)) 253 return false; 254 rc = RTStrValidateEncodingEx((const char *)&pString->String.utf8[0], pString->u16Length + 1, 255 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED); 245 if (RT_LIKELY((uint32_t)pString->u16Size + RT_UOFFSETOF(SHFLSTRING, String) <= cbBuf)) 246 { 247 if (fUtf8Not16) 248 { 249 /* UTF-8: */ 250 if (RT_LIKELY(pString->u16Length < pString->u16Size)) 251 { 252 rc = RTStrValidateEncodingEx((const char *)&pString->String.utf8[0], pString->u16Length + 1, 253 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED); 254 if (RT_SUCCESS(rc)) 255 return true; 256 } 257 } 258 else 259 { 260 /* UTF-16: */ 261 if (RT_LIKELY(!(pString->u16Length & 1))) 262 { 263 if (RT_LIKELY((uint32_t)sizeof(RTUTF16) + pString->u16Length <= pString->u16Size)) 264 { 265 rc = RTUtf16ValidateEncodingEx(&pString->String.ucs2[0], pString->u16Length / 2 + 1, 266 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH 267 | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED); 268 if (RT_SUCCESS(rc)) 269 return true; 270 } 271 } 272 } 273 } 256 274 } 257 else 258 { 259 /* UTF-16: */ 260 if (RT_UNLIKELY(pString->u16Length & 1)) 261 return false; 262 if (RT_UNLIKELY((uint32_t)sizeof(RTUTF16) + pString->u16Length > pString->u16Size)) 263 return false; 264 rc = RTUtf16ValidateEncodingEx(&pString->String.ucs2[0], pString->u16Length / 2 + 1, 265 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED); 266 } 267 if (RT_FAILURE(rc)) 268 return false; 269 return true; 275 return false; 270 276 } 271 277 … … 283 289 if (pString) 284 290 return ShflStringIsValidIn(pString, cbBuf, fUtf8Not16); 285 if (RT_ UNLIKELY(cbBuf >0))286 return false;287 return true;291 if (RT_LIKELY(cbBuf == 0)) 292 return true; 293 return false; 288 294 } 289 295
Note:
See TracChangeset
for help on using the changeset viewer.