<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>

    Unreleased Resource: Android SQLite Database

    ABSTRACT

    Android 活動未能在其 onPause()onStop()onDestroy() 事件處理器中釋放 Android 數據庫處理器。

    EXPLANATION

    Android 活動維護了在 onPause()onStop()onDestroy() 回調中未關閉的 Android SQLite 數據庫處理器。當 Android OS 需要將當前活動發送到后臺或在系統資源不足時暫時中斷活動時,會調用這些回調函數。由于未能正確關閉數據庫,如果活動不斷重啟,則可能會耗盡可用的游標。此外,根據實現方法不同,Android 操作系統也可能拋出異常 DatabaseObjectNotClosedException。如果未能捕獲此異常,應用程序將會崩潰。

    例:以下代碼描述了在停止時會緩存用戶數據并寫入磁盤的 Android 活動。請注意,該活動沒有替代用于釋放數據庫對象的基本 onPause() 方法,也沒有在關機順序中正確釋放該對象。


    public class MyDBHelper extends SQLiteOpenHelper {
    ...
    }

    public class UnreleasedDBActivity extends Activity {
    private myDBHelper dbHelper;
    private SQLiteDatabase db;

    @Override
    public void onCreate(Bundle state) {
    ...
    db = dbHelper.getWritableDatabase();
    ...
    }

    @Override
    public void onRestart() {
    ...
    }

    @Override
    public void onStop() {
    db.insert(cached_data); // flush cached data
    }
    }

    REFERENCES

    [1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A9 Application Denial of Service

    [2] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP6080 CAT II

    [3] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP6080 CAT II

    [4] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 404, CWE ID 619

    [5] Data Storage, Android Developers

    [6] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.9

    [7] Standards Mapping - SANS Top 25 2009 - (SANS 2009) Risky Resource Management - CWE ID 404


    Copyright 2013 Fortify Software - All rights reserved.
    (Generated from version 2013.1.1.0008 of the Fortify Secure Coding Rulepacks)
    desc.structural.java.unreleased_resource_android_sqlite_database

    97av