From 2ab999f4ca46361662e51e1e2740f0a68fb347aa Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 20 Nov 2018 01:50:31 -0500 Subject: [PATCH] Fix bug in DB query wrapper --- native/jni/daemon/db.cpp | 4 ++-- native/jni/include/db.h | 4 ++-- native/jni/su/su_daemon.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/native/jni/daemon/db.cpp b/native/jni/daemon/db.cpp index f0a1769e8..28ce7c8f1 100644 --- a/native/jni/daemon/db.cpp +++ b/native/jni/daemon/db.cpp @@ -195,7 +195,7 @@ static int settings_cb(void *v, int col_num, char **data, char **col_name) { int get_db_settings(db_settings *dbs, int key) { char *err; - if (key > 0) { + if (key >= 0) { char query[128]; sprintf(query, "SELECT key, value FROM settings WHERE key='%s'", DB_SETTING_KEYS[key]); err = db_exec(query, settings_cb, dbs); @@ -225,7 +225,7 @@ static int strings_cb(void *v, int col_num, char **data, char **col_name) { int get_db_strings(db_strings *str, int key) { char *err; - if (key > 0) { + if (key >= 0) { char query[128]; sprintf(query, "SELECT key, value FROM strings WHERE key='%s'", DB_STRING_KEYS[key]); err = db_exec(query, strings_cb, str); diff --git a/native/jni/include/db.h b/native/jni/include/db.h index 1b69d4019..c57181474 100644 --- a/native/jni/include/db.h +++ b/native/jni/include/db.h @@ -136,8 +136,8 @@ struct su_access { ********************/ sqlite3 *get_magiskdb(sqlite3 *&db); -int get_db_settings(db_settings *dbs, int key); -int get_db_strings(db_strings *str, int key); +int get_db_settings(db_settings *dbs, int key = -1); +int get_db_strings(db_strings *str, int key = -1); int get_uid_policy(int uid, struct su_access *su); int validate_manager(char *alt_pkg, int userid, struct stat *st); void exec_sql(int client); diff --git a/native/jni/su/su_daemon.cpp b/native/jni/su/su_daemon.cpp index 7d4f7bebb..acd5b7943 100644 --- a/native/jni/su/su_daemon.cpp +++ b/native/jni/su/su_daemon.cpp @@ -60,8 +60,8 @@ static void *info_collector(void *node) { static void database_check(su_info *info) { int uid = info->uid; - get_db_settings(&info->cfg, 0); - get_db_strings(&info->str, 0); + get_db_settings(&info->cfg); + get_db_strings(&info->str); // Check multiuser settings switch (info->cfg[SU_MULTIUSER_MODE]) {