#define _GNU_SOURCE
+#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
static GList *user_info_list;
+char *string_trim_inplace(char *s) {
+ char *original = s;
+ size_t len = 0;
+
+ while (isspace((unsigned char) *s))
+ s++;
+
+ if (*s) {
+ char *p = s;
+ while (*p)
+ p++;
+ while (isspace((unsigned char) *(--p)));
+ p[1] = '\0';
+ len = (size_t) (p - s + 1);
+ }
+
+ if (len > MAX_QUERY_LEN)
+ return NULL;
+ return (s == original) ? s : memmove(original, s, len + 1);
+}
+
static char *__get_dbpath(uid_t uid)
{
const char *db_path;
char *schema_in_library, *schema_in_db;
static const char table_schema_query[] =
"SELECT sql from sqlite_master WHERE name=?";
- char buf[BUFSIZE];
sqlite3 *db;
+ char *schema_lib_tmp;
+ char *schema_lib_ptr;
+ char *schema_db_tmp;
+ char *schema_db_ptr;
+ char *line_db;
+ char *line_library;
ret = sqlite3_open_v2(db_path, &db,
SQLITE_OPEN_READONLY, NULL);
LOGE("Failed to get initialization query from library");
goto err;
}
+ schema_lib_tmp = strdup(schema_in_library);
+ schema_lib_ptr = schema_lib_tmp;
+ if (schema_lib_tmp == NULL) {
+ LOGE("Out of memory");
+ goto err;
+ }
+
schema_in_db = strstr(check_result, db_tables[i]);
if (schema_in_db == NULL) {
LOGE("Failed to get initialization query from db");
+ free(schema_lib_ptr);
goto err;
}
+ schema_db_tmp = strdup(schema_in_db);
+ schema_db_ptr = schema_db_tmp;
+ if (schema_db_tmp == NULL) {
+ LOGE("Out of memory");
+ free(schema_lib_ptr);
+ goto err;
+ }
+
+ while (true) {
+ line_db = strsep(&schema_db_tmp, ",");
+ line_library = strsep(&schema_lib_tmp, ",");
+ if (line_db == NULL || line_library == NULL)
+ break;
+
+ if (string_trim_inplace(line_db) == NULL ||
+ string_trim_inplace(line_library) == NULL)
+ break;
+
+ ret = strcmp(string_trim_inplace(line_db),
+ string_trim_inplace(line_library));
+ if (ret != 0)
+ break;
+ }
+
+ free(schema_lib_ptr);
+ free(schema_db_ptr);
- ret = strcmp(schema_in_library, schema_in_db);
if (ret != 0) {
LOGE("Broken schema detected in table[%s], query[%s]",
db_tables[i], schema_in_db);