@@ -313,6 +313,9 @@ static const bool has_smb2_data_area[NUMBER_OF_SMB2_COMMANDS] = {
313
313
char *
314
314
smb2_get_data_area_len (int * off , int * len , struct smb2_hdr * shdr )
315
315
{
316
+ const int max_off = 4096 ;
317
+ const int max_len = 128 * 1024 ;
318
+
316
319
* off = 0 ;
317
320
* len = 0 ;
318
321
@@ -384,29 +387,20 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *shdr)
384
387
* Invalid length or offset probably means data area is invalid, but
385
388
* we have little choice but to ignore the data area in this case.
386
389
*/
387
- if (* off > 4096 ) {
388
- cifs_dbg (VFS , "offset %d too large, data area ignored\n" , * off );
389
- * len = 0 ;
390
- * off = 0 ;
391
- } else if (* off < 0 ) {
392
- cifs_dbg (VFS , "negative offset %d to data invalid ignore data area\n" ,
393
- * off );
390
+ if (unlikely (* off < 0 || * off > max_off ||
391
+ * len < 0 || * len > max_len )) {
392
+ cifs_dbg (VFS , "%s: invalid data area (off=%d len=%d)\n" ,
393
+ __func__ , * off , * len );
394
394
* off = 0 ;
395
395
* len = 0 ;
396
- } else if (* len < 0 ) {
397
- cifs_dbg (VFS , "negative data length %d invalid, data area ignored\n" ,
398
- * len );
399
- * len = 0 ;
400
- } else if (* len > 128 * 1024 ) {
401
- cifs_dbg (VFS , "data area larger than 128K: %d\n" , * len );
396
+ } else if (* off == 0 ) {
402
397
* len = 0 ;
403
398
}
404
399
405
400
/* return pointer to beginning of data area, ie offset from SMB start */
406
- if (( * off != 0 ) && ( * len != 0 ) )
401
+ if (* off > 0 && * len > 0 )
407
402
return (char * )shdr + * off ;
408
- else
409
- return NULL ;
403
+ return NULL ;
410
404
}
411
405
412
406
/*
0 commit comments