String Analysis for Code Contracts
Analýza řetězců v Code Contracts
diploma thesis (DEFENDED)

View/ Open
Permanent link
http://hdl.handle.net/20.500.11956/83099Identifiers
Study Information System: 162856
Collections
- Kvalifikační práce [11325]
Author
Advisor
Referee
Kofroň, Jan
Faculty / Institute
Faculty of Mathematics and Physics
Discipline
Software Systems
Department
Department of Distributed and Dependable Systems
Date of defense
5. 9. 2016
Publisher
Univerzita Karlova, Matematicko-fyzikální fakultaLanguage
English
Grade
Excellent
Keywords (Czech)
řetězce, statická analýza, abstraktní interpretace, Code ContractsKeywords (English)
strings, static analysis, abstract interpretation, Code ContractsJedním ze způsobů prevence chyb v objektově orientovaných programech je používání kontraktů, kterými jsou například vstupní a výstupní podmínky metod nebo invarianty tříd. Ve frameworku .NET je používání kontraktů umožněno díky frameworku Code Contracts, který mimo jiné obsahuje nástroj Clousot na statickou analýzu programů, založený na abstraktní interpretaci. Ačkoli řetězce jsou jedním ze základních typů v programech pro .NET, Clousot neobsahuje použitelnou podporu pro analýzu řetězcových hodnot. V této práci probereme specifika práce s řetězci v jazyce C# a frameworku .NET a ukážeme, jak je možné ji pokrýt statickou analýzou. Zvolený přístup využívá metody třídy String a omezenou podmnožinu regulárních výrazů ke specifikaci vlastností řetězců v kódu, a abstraktní interpretaci s nerelačními abstraktními doménami k důkazům těchto vlastností. Zvolili jsme několik již publikovaných abstraktních domén pro řetězce, které se mezi sebou liší složitostí a schopností reprezentovat různé vlastnosti řetězců. Tyto domény jsme adaptovali pro zvolené prostředí, což zahrnovalo definici abstraktní sémantiky pro podporované řetězcové operace. Abstraktní domény jsme implementovali v nástroji Clousot, a to tak, aby bylo v budoucnu možné rozšíření o další domény. Powered by TCPDF (www.tcpdf.org)
Using contracts such as method preconditions, postconditions, and class invariants in code is an approach to preventing bugs in object-oriented programs. In the .NET Framework, this is possible due to the framework of Code Contracts, which includes Clousot, a tool for static program analysis based on abstract interpretation. Although string is a fundamental type in .NET programs, Clousot does not have a usable support for analysis of string values. In this thesis, we explore the specifics of string manipulation in the C# language and in the .NET Framework, and show how they can be covered by static analysis. Our approach is to use the methods of the String class and a subset of regular expressions to specify string properties in code, and to use abstract interpretation with non-relational abstract domains to reason about those properties. We chose a small number of already published abstract domains for strings, which vary in their complexity and ability to represent different properties. We adapted those domains to our setting, including definitions of abstract semantics for the supported string methods. We implemented the abstract domains in Clousot in a way that cooperates with numerical analysis and allows adding more string abstract domains in the future. Powered by TCPDF (www.tcpdf.org)