@@ -324,46 +324,33 @@ private module Persistence {
324
324
* the database. Examples include `create`, `insert`, and `update`.
325
325
*/
326
326
abstract private class ModifyAndSaveCall extends DataFlow:: CallNode , PersistentWriteAccess:: Range {
327
- /**
328
- * Holds if the given key-value pair is set on an object by this call.
329
- */
330
- abstract predicate setsKeyValuePair ( ExprCfgNode key , ExprCfgNode value ) ;
331
-
332
327
/**
333
328
* Gets the ActiveRecord model class to which this call applies.
334
329
*/
335
330
abstract ActiveRecordModelClass getClass ( ) ;
336
-
337
- final override DataFlow:: Node getValue ( ) {
338
- exists ( ExprCfgNode keyExpr , ExprCfgNode valueExpr |
339
- this .setsKeyValuePair ( keyExpr , valueExpr )
340
- |
341
- result .asExpr ( ) = valueExpr
342
- )
343
- }
344
331
}
345
332
346
333
/**
347
334
* Holds if there is a hash literal argument to `call` at `argIndex`
348
- * containing a `key`-` value` pair .
335
+ * containing a KV pair with value ` value`.
349
336
*/
350
- private predicate hashArgument (
351
- DataFlow:: CallNode call , int argIndex , ExprCfgNode key , ExprCfgNode value
337
+ private predicate hashArgumentWithValue (
338
+ DataFlow:: CallNode call , int argIndex , DataFlow :: ExprNode value
352
339
) {
353
340
exists ( ExprNodes:: HashLiteralCfgNode hash , ExprNodes:: PairCfgNode pair |
354
341
hash = call .getArgument ( argIndex ) .asExpr ( ) and
355
342
pair = hash .getAKeyValuePair ( )
356
343
|
357
- key = pair . getKey ( ) and value = pair .getValue ( )
344
+ value . asExpr ( ) = pair .getValue ( )
358
345
)
359
346
}
360
347
361
348
/**
362
- * Holds if `call` has a keyword argument of the form `key: value`.
349
+ * Holds if `call` has a keyword argument of with value ` value`.
363
350
*/
364
- private predicate keywordArgument ( DataFlow:: CallNode call , ExprCfgNode key , ExprCfgNode value ) {
351
+ private predicate keywordArgumentWithValue ( DataFlow:: CallNode call , DataFlow :: ExprNode value ) {
365
352
exists ( ExprNodes:: PairCfgNode pair | pair = call .getArgument ( _) .asExpr ( ) |
366
- key = pair . getKey ( ) and value = pair .getValue ( )
353
+ value . asExpr ( ) = pair .getValue ( )
367
354
)
368
355
}
369
356
@@ -380,10 +367,10 @@ private module Persistence {
380
367
]
381
368
}
382
369
383
- override predicate setsKeyValuePair ( ExprCfgNode key , ExprCfgNode value ) {
370
+ override DataFlow :: Node getValue ( ) {
384
371
// attrs as hash elements in arg0
385
- hashArgument ( this , 0 , key , value ) or
386
- keywordArgument ( this , key , value )
372
+ hashArgumentWithValue ( this , 0 , result ) or
373
+ keywordArgumentWithValue ( this , result )
387
374
}
388
375
389
376
override ActiveRecordModelClass getClass ( ) { result = modelCls }
@@ -398,8 +385,8 @@ private module Persistence {
398
385
this .getMethodName ( ) = [ "update" , "update!" , "upsert" ]
399
386
}
400
387
401
- override predicate setsKeyValuePair ( ExprCfgNode key , ExprCfgNode value ) {
402
- keywordArgument ( this , key , value )
388
+ override DataFlow :: Node getValue ( ) {
389
+ keywordArgumentWithValue ( this , result )
403
390
or
404
391
// Case where 2 array args are passed - the first an array of IDs, and the
405
392
// second an array of hashes - each hash corresponding to an ID in the
@@ -412,7 +399,7 @@ private module Persistence {
412
399
hash = hashesArray .getArgument ( _) and
413
400
pair = hash .getAKeyValuePair ( )
414
401
|
415
- key = pair . getKey ( ) and value = pair .getValue ( )
402
+ result . asExpr ( ) = pair .getValue ( )
416
403
)
417
404
)
418
405
}
@@ -431,13 +418,13 @@ private module Persistence {
431
418
arr = this .getArgument ( 0 ) .asExpr ( )
432
419
}
433
420
434
- override predicate setsKeyValuePair ( ExprCfgNode key , ExprCfgNode value ) {
421
+ override DataFlow :: Node getValue ( ) {
435
422
// attrs as hash elements of members of array arg0
436
423
exists ( ExprNodes:: HashLiteralCfgNode hash , ExprNodes:: PairCfgNode pair |
437
424
hash = arr .getArgument ( _) and
438
425
pair = hash .getAKeyValuePair ( )
439
426
|
440
- key = pair . getKey ( ) and value = pair .getValue ( )
427
+ result . asExpr ( ) = pair .getValue ( )
441
428
)
442
429
}
443
430
@@ -451,12 +438,12 @@ private module Persistence {
451
438
this .getMethodName ( ) = [ "update" , "update!" , "update_attributes" , "update_attributes!" ]
452
439
}
453
440
454
- override predicate setsKeyValuePair ( ExprCfgNode key , ExprCfgNode value ) {
441
+ override DataFlow :: Node getValue ( ) {
455
442
// attrs as hash elements in arg0
456
- hashArgument ( this , 0 , key , value )
443
+ hashArgumentWithValue ( this , 0 , result )
457
444
or
458
445
// keyword arg
459
- keywordArgument ( this , key , value )
446
+ keywordArgumentWithValue ( this , result )
460
447
}
461
448
462
449
override ActiveRecordModelClass getClass ( ) { result = this .getInstance ( ) .getClass ( ) }
@@ -466,9 +453,9 @@ private module Persistence {
466
453
private class UpdateAttributeCall extends ModifyAndSaveCall , ActiveRecordInstanceMethodCall {
467
454
UpdateAttributeCall ( ) { this .getMethodName ( ) = "update_attribute" }
468
455
469
- override predicate setsKeyValuePair ( ExprCfgNode key , ExprCfgNode value ) {
456
+ override DataFlow :: Node getValue ( ) {
470
457
// e.g. `foo.update_attribute(key, value)`
471
- key = this .getArgument ( 0 ) . asExpr ( ) and value = this . getArgument ( 1 ) . asExpr ( )
458
+ result = this .getArgument ( 1 )
472
459
}
473
460
474
461
override ActiveRecordModelClass getClass ( ) { result = this .getInstance ( ) .getClass ( ) }
0 commit comments