SE547: Security Automata: Limit Open Files [19/20] |
class LimitFiles extends Policy { private int openFiles = 0; private int maxOpen = 0; LimitFiles(int max) { maxOpen = max; } Suggestion query(Action a) { aswitch (a) { case <* *.*.fileOpen(..)>: if (++openFiles <= maxOpen) return Suggestion.OK(); else return Suggestion.Halt(); case <* *.*.fileClose(..)>: --openFiles; return Suggestion.OK(); default: return new UnregSuggestion(this, a); } } }