skip to main content
article

Static checking of dynamically generated queries in database applications

Published:01 September 2007Publication History
Skip Abstract Section

Abstract

Many data-intensive applications dynamically construct queries in response to client requests and execute them. Java servlets, for example, can create strings that represent SQL queries and then send the queries, using JDBC, to a database server for execution. The servlet programmer enjoys static checking via Java's strong type system. However, the Java type system does little to check for possible errors in the dynamically generated SQL query strings. Thus, a type error in a generated selection query (e.g., comparing a string attribute with an integer) can result in an SQL runtime exception. Currently, such defects must be rooted out through careful testing, or (worse) might be found by customers at runtime. In this article, we present a sound, static program analysis technique to verify that dynamically generated query strings do not contain type errors. We describe our analysis technique and provide soundness results for our static analysis algorithm. We also describe the details of a prototype tool based on the algorithm and present several illustrative defects found in senior software-engineering student-team projects, online tutorial examples, and a real-world purchase order system written by one of the authors.

References

  1. Aho, A., Sethi, R., and Ullman, J. 1986. Compilers, Principles, Techniques and Tools. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Amadio, R., and Cardelli, L. 1991. Subtyping recursive types. In Proceedings of the 18th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Orlando, FL). ACM, New York, 104--118. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Andersen, L. 1994. Program analysis and specialization for the C programming language. Ph.D. thesis, DIKU, University of Copenhagen. DIKU report 94/19.Google ScholarGoogle Scholar
  4. Braband, C., Møller, A., and Schwartzbach, M. 2001. Static validation of dynamically generated HTML. In ACM SIGPLAN--SIGSOFT Workshop on Program Analysis for Software Tools and Engineering (Snowbird, UT). ACM, New York, 38--45. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Brabrand, C., M&oslah;ller, A., and Schwartzbach, M. 2002. The <bigwig> project. ACM Trans. Internet Tech. 2, 2, 79--114. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Choi, T.-H., Lee, O., Kim, H., and Doh, K.-G. 2006. A practical string analyzer by the widening approach. In Proceedings of the 4th Asian Symposium on Programming Languages and Systems (APLAS 2006) (Sydney, Australia). Springer-Verlag, New York, 374--388. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Christensen, A., M&oslah;ller, A., and Schwartzbach, M. 2003. Precise analysis of string expressions. In Proceedings of the 10th International Static Analysis Symposium (San Diego, CA). Springer-Verlag, New York, 1--18. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Cook, W. R., and Ibrahim, A. H. 2005. Programming languages & databases: What's the problem?? url: http://www.cs.utexas.edu/~wcook/Drafts/2005/PLDBProblem.pdf.Google ScholarGoogle Scholar
  9. Cook, W. R., and Rai, S. 2005. Safe query objects: Statically typed objects as remotely executable queries. In Proceedings of the 27th International Conference on Software Engineering (ICSE) (St. Louis, MO). ACM, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Guyot, J. 1998. BNF index of SQL for Oracle 7. Available at http://cui.unige.ch/db-research/Enseignement/analyseinfo/SQL7/.Google ScholarGoogle Scholar
  11. Halfond, W. G., and Orso, A. 2005. Combining static analysis and runtime monitoring to counter SQL-injection attacks. In Proceedings of the 3rd International ICSE Workshop on Dynamic Analysis (WODA 2005) (St. Louis, MO). ACM, New York. url: http://www.csd.uwo.ca/woda2005/proceedings.html. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Heintze, N., and Tardieu, O. 2001. Ultra-fast aliasing analysis using CLA: A million lines of C code in a second. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (Snowbird, UT). ACM, New York, 254--263. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Hopcroft, J., and Ullman, J. 1979. Introduction to Automata Theory, Language, and Computation. Addison--Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. JBoss. 2006. Hibernate. url: http://www.hibernate.org/.Google ScholarGoogle Scholar
  15. Kam, J., and Ullman, J. 1976. Global data flow analysis and iterative algorithms. J. ACM 23, 1 (Jan.), 158--171. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Kapfhammer, G. M., and Soffa, M. L. 2003. A family of test adequacy criteria for database-driven applications. In Proceedings of the 9th European Software Engineering Conference and the 11th ACM SIGSOFT Symposium on Foundations of Software Engineering (Helsinki, Finland). ACM, New York, 98--107. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Kildall, G. 1973. A unified approach to global program optimization. In Conference Record of the ACM SIGACT and SIGPLAN Symposium on Principles of Programming Languages (Boston, MA). ACM, New York, 194--206. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Kohlbecker, E., Friedman, D., Felleisen, M., and Duba, B. 1986. Hygenic macro expansion. In Proceedings of the 1986 ACM Conference on LISP and Functional Programming (Cambridge, MA). ACM, New York, 151--159. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Melski, D., and Reps, T. 1997. Interconvertibility of set constraints and context-free language reachability. In Proceedings of the 1997 ACM Symposium on Partial Evaluation and Semantics-Based Program Manipulation, PEPM'97 (Amsterdam, The Netherlands). ACM, New York, 74--89. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Microsoft. 2004. ADO.NET. url: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/adonetanchor.asp.Google ScholarGoogle Scholar
  21. Microsoft. 2005. LINQ Project. url: http://msdn.microsoft.com/netframework/future/linq/.Google ScholarGoogle Scholar
  22. Oracle. 2006. Oracle TopLink. url: http://www.oracle.com/technology/products/ias/toplink/index.html.Google ScholarGoogle Scholar
  23. Reps, T., Horwitz, S., and Sagiv, M. 1995. Precise interprocedural dataflow analysis via graph reachability. In Proceedings of the 22nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (San Francisco, CA). ACM, New York, 49--61. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Sandholm, A., and Schwartzbach, M. 2000. A type system for dynamic web documents. In Proceedings of the 27th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Boston, MA). ACM, New York, 290--301. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Shivers, O. 1988. Control flow analysis in Scheme. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (Atlanta, GA). ACM, New York, 164--174. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. SQLJ. 1997. See http://www.sqlj.org.Google ScholarGoogle Scholar
  27. Su, Z., Fähndrich, M., and Aiken, A. 2000. Projection merging: Reducing redundancies in inclusion constraint graphs. In Proceedings of the 27th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Boston, MA). ACM, New York, 81--95. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Sun. 2003. Java Data Objects (JDO). url: http://java.sun.com/products/jdo/. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Taha, W., and Sheard, T. 1997. Multi-stage programming with explicit annotations. In Proceedings of the ACM-SIGPLAN Symposium on Partial Evaluation and Semantic Based Program Manipulations (Amsterdam, The Netherlands). ACM, New York, 203--217. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Vallee-Rai, R., Hendren, L., Sundaresan, V., Lam, P., Gagnon, E., and Co, P. 1999. Soot--a Java optimization framework. In Proceedings of the IBM Centre for Advanced Studies Conference, CASCON'99 (Mississauga, Ont., Canada). IBM, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Viega, J., and McGraw, G. 2001. Building Secure Software: How to Avoid Security Problems the Right Way. Addison Wesley, Boston, MA.Google ScholarGoogle Scholar
  32. Wassermann, G., and Su, Z. 2004. An analysis framework for security in Web applications. In Proceedings of the 3rd FSE Workshop on the Specification and Verification of Component Based Systems (SAVCBS 2004) (Newport Beach, CA). ACM, New York, 70--78.Google ScholarGoogle Scholar
  33. Weise, D., and Crew, R. 1993. Programmable syntax macros. In Proceedings of the SIGPLAN Conference on Programming Language Design and Implementation (Albuquerque, NM). ACM, New York, 156--165. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Yellin, D. 1993. Speeding up dynamic transitive closure for bounded degree graphs. Acta Inf. 30, 4 (July), 369--384.Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Static checking of dynamically generated queries in database applications

                  Recommendations

                  Comments

                  Login options

                  Check if you have access through your login credentials or your institution to get full access on this article.

                  Sign in

                  Full Access

                  PDF Format

                  View or Download as a PDF file.

                  PDF

                  eReader

                  View online with eReader.

                  eReader