
17778 R.Singh et al./ Elixir Comp. Sci. & Engg. 62 (2013) 17778-17782 Available online at www.elixirpublishers.com (Elixir International Journal) Computer Sciences and Engineering Elixir Comp. Sci. & Engg. 62 (2013) 17778-17782 A comparative study of buffer overflow anomaly in Java using findbugs, PMD and checkstyle R.Singh 1, Rajnish Dashora 2,* and Shiven Saiwal 2 1NIC, New Delhi, India. 2School of Computing Sciences and Engineering, VIT University, Vellore, India. ARTICLE INFO ABSTRACT Article history: Static analysis means examining a program code and overcoming all possible errors that Received: 27 July 2013; tend to occur at run-time. Static analysis tools are efficient in finding bugs and correction of Received in revised form: defects that arise due to improper functioning of the code, before the actual execution of the 25 August 2013; code [10]. In recent times, technology has facilitated us with new tools that do deeper and Accepted: 9 September 2013; more efficient code analysis and have a higher defect detection rate along with low fake warning ratio. This paper aims to deal with buffer overrun anomalies occurring in many Keywords areas of source code in Java. Static Analysis; © 2013 Elixir All rights reserved Buffer Overrun; Legacy Code; Error Detection Efficiency, Cyclomatic Complexity; Null Pointer Derefrencing; Null Pointer Execption; Bugs. Introduction Static analysis tools that have been used in the research to A few decades back, there was no formal method of debug the source code are: 1) Findbugs, which analyses Java reviewing source code for software development. Later, an byte code and produces different types of potential errors. inspection procedure was introduced, termed as “manual Potential errors are classified into ranks i.e. a) scariest, b) scary, reviewing”, accepted as the formalized reviewing methodology. c) troubling, d) of concern. It reports errors like dead code It’s importance is that it provides information about software elimination, deadlock detection, null pointer referencing and productivity and quality. For the inspection phase, Fagan has dereferencing 2) PMD (Programming Mistake Detector), which given an expression to calculate error detection efficiency i.e. is a static rule set based Java code analyzer that deals with [1] problems like a) empty try/catch block, b) Dead code, c) empty Error detection efficiency = (error found by an inspection / conditional and looping statements, d) complicated expression, total errors before inspection)*100. e) wasteful string buffer usage, f) classes with high cyclomatic The best way to debug a program is to use static analysis complexity measurements and g) duplicate code. 3)Checkstyle, tools which maximize the program efficiency by quick analysis which compiles Java code in such a manner so as to result in and correction of defects. The static analysis approach is meant good programming practices which improve the code quality, to check the source code, compliance of the rules, usage of readability, reusability and reduce the cost of development. It arguments, dynamic inconsistency, dead code, coding standards does not analyze the correctness of code but deals with style and also to be able to find bug patterns [2]. constraints that are needed for certain programs. It permits to The major question that arises is whether testing should check a) Naming conventions, b) limit function parameters, c) precede reviewing or vice versa. Thus, this paper is organized in header files, d) spaces between characters etc [4]. Nowadays, various sections - Section II: Static Analysis Approach, Section these tools come together in a single package known as SONAR III: Manual Reviewing Process, Section IV: Experimental Tools, that is efficient in performing the mentioned tasks collectively. Section V: Comparison of Static Analysis Tools, Section VI: Through this analysis, we can reduce the loss of data by Related works important to understand the literature behind avoiding wasteful buffer usage, infinite loops, and inappropriate static analysis of code using bug finding tools. Section VII: conditional and looping statements. In this way we may Improvements in existing tools, Section VIII: Conclusion over overcome the buffer overrun anomaly [5]. static code analysis tool for software development. Several lines of Java code were tested by the above Static Analysis Approach mentioned tools and their behavior towards buffer overrun was Major concern is shown over the Java programming noted. A comparative study is also shown between static and language as it is considered an object oriented language but still dynamic analysis techniques. Lastly, some suggestions are also is not able to deal with buffer overrun anomaly and tends to made for the improvement of the existing tools which would aid produce defects like “stack overflow” and “overridden in further maximizing program efficiency [4]. methods”. Tele: E-mail addresses: [email protected] © 2013 Elixir All rights reserved 17779 R.Singh et al./ Elixir Comp. Sci. & Engg. 62 (2013) 17778-17782 Buffer overrun: It is an anomaly in which a program, while Experimental tools writing data to buffer, overruns the buffer boundary and writes Three tools were used to analyze a static buffer overflow in to the adjacent boundary and violates the memory safety. For Java code and results were analyzed. example, Char A[8]; \\ A having value null string; Unsigned Findbugs short B; \\ b having value 1212 [15]. It is a tool that analyzes byte code and produces bug patterns. It is comparatively faster than other tools as it works on variable name A B byte code. It often finds real defects and also has low false defect rates. There are a maximum of 414 rules declared in Value [null string] 1212 Findbugs under the rule categories i.e. Correctness, Dodgy hex value 00 00 00 00 00 00 00 00 0C 0C Code, Bad Practice, Multithread Correctness, Performance Malicious, Code Vulnerability, Security Experimental and Figure 1: Variable Buffer Internalization. Strcpy (A,”excessive”); // as excessive is of 9 character it Weakness: It is not aware of the sources and needs a overruns the buffer and takes space of buffer B and change its compiled code. Sometimes it also issues warnings that do not value to 25856 correspond to real bugs in which cases the percentage of these variable name A B warnings needs to be made small [11][12]. Example 1: Null Pointer Derefrencing Value 'e' 'x' 'c' 'e' 's' 's' 'i' 'v' 25856 Hex 65 78 63 65 73 73 69 76 65 00 Figure 2: Buffer Overflow Legacy code: It is a source code that is deprecated leading to vulnerabilities or threats [15]. B. Cyclomatic complexity: Cyclomatic complexity is computed using the control flow graph of the program where the nodes of the graph correspond to indivisible groups of commands of a program, and a directed edge connects two nodes. Cyclomatic complexity may also be applied to Figure 4: Null Pointer Derefrencing individual functions, modules, methods or classes within a A pointer which is null on an exception path is dereferenced program [15]. here. This will lead to NullPointerException when code is Assume M is the complexity of control flow graph executed. (Directed Graph). Note: Findbugs sometimes does not prune infeasible M = E – N + 2P exception paths and hence may cause false warnings. Where, Example 2: Method to concatenate strings using + in a E = the number of edges of the graph loop. N = the number of nodes of the graph The method seems to be building a String using P = the number of connected components (exit nodes). concatenation in a loop. Here, the String is converted to a Manual Reviewing StringBuffer and converted back to a String. This can lead to Manual reviewing is a static analysis process that is very quadratic cost in terms of the number of iterations as the time consuming and before going to examine the code, human growing string is recopied every time. auditors need to have sufficient knowledge about the errors they Better performance can be obtained using a StringBuffer are going to analyze. Reviewing is not only the analysis of code explicitly. but also includes documentation, requirements and designs // Bad Practice produced by developers as parts of the reviewing process. This String a = " "; is because there can be hidden errors at each step of software for (int i = 0; i < field.length; ++i) { development process [3]. a = a + field[i]; Manual reviewing is divided into 4 steps- (1)Self Review, } in which the developer debugs his/her own code and gets it rectified, (2)Walkthrough, which refers to the way to present // Better Practice work to audience, (3)Peer-review, which refers to reviewing StringBuffer a = new StringBuffer(); done by colleagues and (4) Final auditing, which is the for (int i = 0; i < field.length; ++i) { reviewing done by higher committee members. a.append(field[i]); } String b = a.toString(); Display (b); Example 3: Hardcode Constant Database Password Figure 3: Manual Reviewing Process Figure 5: Hardcode Constant Database Password 17780 R.Singh et al./ Elixir Comp. Sci. & Engg. 62 (2013) 17778-17782 This bug is reported because anyone with access to source Code above states the sun produced coding conventions. code or compiled code can easily learn the password. To Comparison between Static Analysis tools overcome this defect, we must provide variable password Tabulated results of Static analyses of JAVA code using instead of a static one. software testing tools for JAVA applications. Programming Mistake Detector(PMD) Java analysis tool report It is a tool that looks for potential problems, possible bugs Tools Analyzed Features Efficiency and sub optimal code and highly complicated expressions in a Static analyses of byte Java source code. It occasionally finds real defects and bad Findbugs code, false warnings, 37.5% practice bugs. It has maximum of 234 rules in its rule categories misunderstood API i.e. JSP, XSL, JAVA, Ecmascript and XML.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-