File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-764/semmle/tests Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 7
7
| test.cpp:303:11:303:18 | call to try_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
8
8
| test.cpp:313:11:313:18 | call to try_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
9
9
| test.cpp:442:8:442:17 | call to mutex_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
10
+ | test.cpp:482:2:482:19 | call to pthread_mutex_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
Original file line number Diff line number Diff line change @@ -445,3 +445,46 @@ bool test_mutex(data_t *data)
445
445
446
446
return true ;
447
447
}
448
+
449
+ // ---
450
+
451
+ struct pthread_mutex
452
+ {
453
+ // ...
454
+ };
455
+
456
+ void pthread_mutex_lock (pthread_mutex *m);
457
+ void pthread_mutex_unlock (pthread_mutex *m);
458
+
459
+ class MyClass
460
+ {
461
+ public:
462
+ pthread_mutex lock;
463
+ };
464
+
465
+ bool maybe ();
466
+
467
+ int test_MyClass_good (MyClass *obj)
468
+ {
469
+ pthread_mutex_lock (&obj->lock );
470
+
471
+ if (maybe ()) {
472
+ pthread_mutex_unlock (&obj->lock );
473
+ return -1 ; // GOOD
474
+ }
475
+
476
+ pthread_mutex_unlock (&obj->lock ); // GOOD
477
+ return 0 ;
478
+ }
479
+
480
+ int test_MyClass_bad (MyClass *obj)
481
+ {
482
+ pthread_mutex_lock (&obj->lock );
483
+
484
+ if (maybe ()) {
485
+ return -1 ; // BAD
486
+ }
487
+
488
+ pthread_mutex_unlock (&obj->lock ); // GOOD
489
+ return 0 ;
490
+ }
You can’t perform that action at this time.
0 commit comments