Enhancing Mobile Development with Klocwork Checkers for Android

Similar documents
Effective Software Verification for Medical Devices

Sensors CS 4720 Web & Mobile Systems

Lecture 1 Introduction to Android

ODROID Multithreading in Android

A Short Introduction to Android

Issues in Android on Mobile Platform and Their Resolution

Android Development. Marc Mc Loughlin

Android Basics. Xin Yang

Threat Modeling for Secure Embedded Software

Introduction to Android Development. Jeff Avery CS349, Mar 2013

TOP 3 STRATEGIES TO REDUCE RISK IN AUTOMOTIVE/IN-VEHICLE SOFTWARE DEVELOPMENT

Creating and Using Databases for Android Applications

Frameworks & Android. Programmeertechnieken, Tim Cocx

GETTING STARTED WITH ANDROID DEVELOPMENT FOR EMBEDDED SYSTEMS

Workshop on Android and Applications Development

The power of root on Android emulators

How to develop your own app

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

An Introduction to Android

A B S T R A C T. Keywords: Mobile computing, Compiler, Android Development tool kit; I. INTRODUCTION

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Overview of CS 282 & Android

Bridging the Gap between Mobile Product Development and Customer Experience: Seven Imperatives for IT Organizations

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

Introduction to Android

Creating a 2D Game Engine for Android OS. Introduction

Eclipse Exam Scripting

Технологии Java. Android: Введение. Кузнецов Андрей Николаевич. Санкт-Петербургский Государственный Политехнический Университет

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

ITG Software Engineering

Data on Kernel Failures and Security Incidents

VDI, THE NEXT GENERATION OR THE FINAL FRONTIER?

Pattern Insight Clone Detection

How to Avoid the 10 BIGGEST MISTAKES. in Voice Application Development

Android Mobile App Building Tutorial

Android Architecture. Alexandra Harrison & Jake Saxton

CS 528 Mobile and Ubiquitous Computing Lecture 2: Android Introduction and Setup. Emmanuel Agu

2. Click the download button for your operating system (Windows, Mac, or Linux).

Windows Server 2003 migration: Your three-phase action plan to reach the finish line

TUTORIALS AND QUIZ ANDROID APPLICATION SANDEEP REDDY PAKKER. B. Tech in Aurora's Engineering College, 2013 A REPORT

Introduction to NaviGenie SDK Client API for Android

The Design of the Inferno Virtual Machine. Introduction

Mono for Android Activity Lifecycle Activity Lifecycle Concepts and Overview

Coverity White Paper. Reduce Your Costs: Eliminate Critical Security Vulnerabilities with Development Testing

Solution Provider Lights Up Its Industrial Automation Software on Windows 7

The 2014 Bottleneck Report on Enterprise Mobile

How Technology Executives are Managing the Shift to BYOD

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

ANDROID BASED MOBILE APPLICATION DEVELOPMENT and its SECURITY

Android Programming and Security

Building Motion and Noise Detector Networks from Mobile Phones

Magellan. 5 Simple Steps to Finding the Right Mobile Development Magellan Holdings, LLC.

Figure 1: Graphical example of a mergesort 1.

Learning Course Curriculum

TUTORIAL. BUILDING A SIMPLE MAPPING APPLICATION

3 Reasons Xamarin is Best for Mobile App Development

Lua as a business logic language in high load application. Ilya Martynov ilya@iponweb.net CTO at IPONWEB

Developing And Marketing Mobile Applications. Presented by: Leesha Roberts, Senior Instructor, Center for Education Programmes, UTT

Chapter 2 Getting Started

Hacking your Droid ADITYA GUPTA

User Tutorial on Changing Frame Size, Window Size, and Screen Resolution for The Original Version of The Cancer-Rates.Info/NJ Application

Development Testing for Agile Environments

Understanding barcodes. White paper

Who, What, Where, How: Five Big Questions in Mobile Security

Thirsting for ideas to help your restaurant grow?

Here to take you beyond Mobile Application development using Android Course details

Disclaimer: The contents in this document are only my personal opinions, do not reflect the opinions of my employer or anyone else.

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

A Modular Approach to Teaching Mobile APPS Development

Dr. Dimitar Valtchev. 24 June 2010, Stuttgart, Eclipse Embedded Day

Azul's Zulu JVM could prove an awkward challenge to Oracle's Java ambitions

Research and Design of Universal and Open Software Development Platform for Digital Home

An Android-based Instant Message Application

An Evaluation of No-Cost Business Intelligence Tools. Claire Walsh

collaboration Keeping people in touch efficiently

How to Program an Android Application to Access and Manage the Wi-Fi Capabilities of a Smartphone

DEVELOPING MOBILE APPLICATIONS USING ANDROID

Android Development: Part One

BYOD Policy Implementation Guide. February 2016 March 2016

The modern marketer s guide to global content creation

Stack Allocation. Run-Time Data Structures. Static Structures

E-Commerce on Android OS

C a p a b i l i t i e s

Business Protection. Personal Privacy. One Device. Enhanced Security for Your Network and Business Intelligence.

OPC UA App development for Android

high-performance computing so you can move your enterprise forward

An Introduction to Android. Huang Xuguang Database Lab. Inha University

Communications Cloud Product Enhancements February 2016

The State of IT Transformation An Analysis by EMC and VMware

RoverPal - A Mobile Payment Application

OSAS version 8 A foundation for the future

Data Management for Portable Media Players

PAYMENTS AND HOSPITALITY. globalpaymentsinc.co.uk

Introduction to Android. CSG250 Wireless Networks Fall, 2008

A Guide To Evaluating Desktop Virtualization Solutions

μsoho PBX for small business or home

Mobile Phones Operating Systems

Car Cybersecurity: What do the automakers really think? 2015 Survey of Automakers and Suppliers Conducted by Ponemon Institute

Transcription:

KLOCWORK WHITE PAPER OCTOBER 2013 Enhancing Mobile Development with Klocwork Checkers for Android Developers in various parts of the Android stack have unique security and error detection needs. The kernel and platform developers that use C and C++ on Linux are focused primarily on performance, stability, and security. Application developers who use Java are more interested in functionality and the user experience. While there are some overlaps in some areas, such as security, the ways in which developers achieve these results are different. Many analysis tools fail to recognize these unique challenges, leaving Android developers code vulnerable to security weaknesses and errors. Klocwork Insight analyzes how the Android code is meant to operate by building a knowledge base of every function call in the platform. This analysis provides an understanding of both the Java and C/C++ code that Android developers require. The analysis is performed on a server or the developer s desktop, and has built-in diagnostics and Android-specific checkers. Android-specific checkers Errors can be tricky to find, which is why Klocwork Insight comes with built-in Java and Androidspecific checkers, including: ANDROID.NPE Null pointer exceptions: These red herring errors are annoying, but have to be fixed or they ll bite your ankles. Fortunately, Klocwork Insight detects them right on your desktop before they infect the build. Here s an example of the more loathsome varieties of NPE trying to load a bitmap: public Bitmap loadbitmap(byte [] data) { Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length); // Align bitmap to 4 pixel boundary final Bitmap resized = Bitmap.createScaledBitmap(bmp, (bmp.getwidth() % 4) * 4, bmp.getheight(), true); return resized; When Klocwork Insight sees code like this, it will highlight the offending line inside your IDE, whether you are using Eclipse or IntelliJ IDEA.

As you no doubt are aware, the pointer from an SDK function isn t guaranteed to be valid. Most developers hate adding defensive checks, but it beats getting a call from the CTO on a Saturday afternoon because your app is crashing. To fix this sample, simply test for null as shown below: public Bitmap loadbitmap(byte [] data) { Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length); if (bmp == null) return null; // Align bitmap to 4 pixel boundary final Bitmap resized = Bitmap.createScaledBitmap(bmp, (bmp.getwidth() % 4) * 4, bmp.getheight(), true); return resized; ANDROID.RLK.SQLCON Resource Allocation: This is one of those snake in the grass errors that surprise many of us. The SQLite commands in the Android SDK return a live connection that continues to live after the variable that contains it goes out of scope. Multiple iterations through the same code will result in slow performance as more memory is devoted to storing idle connections. Here s an example: protected void onresume(bundle bundle) { super.onresume(); final SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase( students.db, null, null); db.execsql( Robert ); DROP TABLE Students;-- ); Enhancing Mobile Development with Klocwork Checkers for Android Klocwork White Paper 2

There are two solutions to this issue. The immediate solution is to close the database connection in the same scope it is opened, as shown below. protected void onresume(bundle bundle) { super.onresume(); final SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase( students.db, null, null); db.execsql( Robert ); DROP TABLE Students;-- ); db.close(); A better practice would be to refactor the database connection to the widest scope that s needed. Opening a database connection has a considerable amount of overhead, so either keep the connection persistent or load the data you need from the database into a local collection and close it. JD.INF.AREC Recursion: Some of the Android lifecycle methods expect you to call their superclass method. If you aren t paying attention, you can create a circular reference to your own code. The compiler is perfectly happy generating code from the following snippet. protected void oncreate(bundle bundle) { oncreate(bundle); Inside the IDE, you ll get a warning that your code has a problem. The solution is to call the superclass version of oncreate() as shown below. protected void oncreate(bundle bundle) { super.oncreate(bundle); ANDROID.UF.* Invalid Resource: Android allows developers to access hardware by instantiating an object that is subclassed from the Android base class. This includes the camera as well as media playback and recording. If the object is released, explicitly or implicitly, the reference to the hardware device is no longer valid. The ANDROID.UF group of checkers detects and reports on these potential errors. Enhancing Mobile Development with Klocwork Checkers for Android Klocwork White Paper 3

public boolean onlongclick(view view) { MediaRecorder mrecorder = new MediaRecorder(); mrecorder.setaudiosource(mediarecorder.audiosource.mic); mrecorder.setoutputformat(mediarecorder.outputformat.three_gpp); mrecorder.setaudioencoder(mediarecorder.audioencoder.amr_nb); final File file = new File( test.raw ); if (file.exists()) else mrecorder.setoutputfile(file.getpath()); mrecorder.start(); return true; While the pointer (mrecorder) isn t null, the object it refers to is no longer valid. The developer needs to spend some time refactoring the code for a better flow, but the most immediate solution to this problem is to exit the function when the pointer is released. By the way, there is also an ANDROID.NPE error in that sample. Can you spot it? Here is a solution to the issues reported: public boolean onlongclick(view view) { MediaRecorder mrecorder = new MediaRecorder(); if (mrecorder == null) return false; mrecorder.setaudiosource(mediarecorder.audiosource.mic); mrecorder.setoutputformat(mediarecorder.outputformat.three_gpp); mrecorder.setaudioencoder(mediarecorder.audioencoder.amr_nb); final File file = new File( test.raw ); if (file.exists()) { return false; mrecorder.setoutputfile(file.getpath()); mrecorder.start(); return true; Klocwork s commitment to Android Over half of all smartphones sold today use Android, and it s a popular choice for embedded systems. The Android-specific checkers above demonstrate Klocwork s commitment to Android developers, and you can expect more from us in the months to come. Other Resources Learn more about Klocwork solutions for Android application and device development. Visit the Klocwork Developer Network to see a list of checkers for Android and examples that show you the best way to remedy security vulnerabilities, even if you ve never heard of them before. See how easily you can write secure, reliable Android code by signing up for a free trial of Klocwork Insight. Enhancing Mobile Development with Klocwork Checkers for Android Klocwork White Paper 4

Klocwork: Empowering developers at their desktop Unlike other source code analysis tools, Insight works in the developer s IDE of choice, identifying security weaknesses and errors so they can be fixed before being committed to the build. We don t make you wait until after a build is run to show you potential security vulnerabilities or reliability issues, we show you On-the-Fly as you are typing. You take corrective action immediately, and submit more secure, reliable code into the build process. Using information from the integration project Insight works behind the scenes collecting all the information needed to analyze your code within the context of the entire build taxonomies, security, coding standards, etc. You review the results, fixing errors and setting others to be fixed later or to be ignored, and adding comments to explain your changes. The result is secure code, fewer errors, and faster project completion. About Klocwork In the world of AppSec, developers and the firms that employ them demand tools that provide a competitive edge. Klocwork meets these demands with compelling desktop tools that enable developers to produce secure, reliable software more easily and quickly. Klocwork s unique SCA tool provides accurate, reliable analysis as developers write their code, identifying potential security vulnerabilities and reliability issues before they are submitted to the software build. Additional desktop tools simplify code review, refactoring and architectural analysis. More than 1,100 customers, including the biggest brands in the automotive, consumer electronics, gaming, medical technologies, military and aerospace, mobile device and telecom sectors rely on these tools everyday to make their software more secure and reliable. Creating applications they are proud of. Find out more at www.klocwork.com. IN THE UNITED STATES: 15 New England Executive Park Burlington, MA 01803 IN CANADA: 30 Edgewater Street, Suite 114 Ottawa, ON K2L 1V8 t: 1.866.556.2967 f: 613.836.9088 WWW.KLOCWORK.COM Klocwork Inc. All rights reserved.