Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed SQL injection vulnerability #2281

Merged
merged 1 commit into from Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -94,14 +94,14 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection,

SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(FORMS_TABLE_NAME);
qb.setProjectionMap(sFormsProjectionMap);
qb.setStrict(true);

switch (sUriMatcher.match(uri)) {
case FORMS:
qb.setProjectionMap(sFormsProjectionMap);
break;

case FORM_ID:
qb.setProjectionMap(sFormsProjectionMap);
qb.appendWhere(FormsColumns._ID + "="
+ uri.getPathSegments().get(1));
break;
Expand Down Expand Up @@ -360,13 +360,21 @@ public int delete(@NonNull Uri uri, String where, String[] whereArgs) {
}
}

String[] newWhereArgs;
if (whereArgs == null || whereArgs.length == 0) {
newWhereArgs = new String[] {formId};
} else {
newWhereArgs = new String[(whereArgs.length + 1)];
newWhereArgs[0] = formId;
System.arraycopy(whereArgs, 0, newWhereArgs, 1, whereArgs.length);
}

count = db.delete(
FORMS_TABLE_NAME,
FormsColumns._ID
+ "="
+ formId
+ "=?"
+ (!TextUtils.isEmpty(where) ? " AND (" + where
+ ')' : ""), whereArgs);
+ ')' : ""), newWhereArgs);
break;

default:
Expand Down Expand Up @@ -510,14 +518,22 @@ public int update(Uri uri, ContentValues values, String where,
values.put(FormsColumns.DISPLAY_SUBTEXT, ts);
}

String[] newWhereArgs;
if (whereArgs == null || whereArgs.length == 0) {
newWhereArgs = new String[] {formId};
} else {
newWhereArgs = new String[(whereArgs.length + 1)];
newWhereArgs[0] = formId;
System.arraycopy(whereArgs, 0, newWhereArgs, 1, whereArgs.length);
}

count = db.update(
FORMS_TABLE_NAME,
values,
FormsColumns._ID
+ "="
+ formId
+ "=?"
+ (!TextUtils.isEmpty(where) ? " AND ("
+ where + ')' : ""), whereArgs);
+ where + ')' : ""), newWhereArgs);
} else {
Timber.e("Attempting to update row that does not exist");
}
Expand Down
Expand Up @@ -91,14 +91,14 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection, Str

SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(INSTANCES_TABLE_NAME);
qb.setProjectionMap(sInstancesProjectionMap);
qb.setStrict(true);

switch (sUriMatcher.match(uri)) {
case INSTANCES:
qb.setProjectionMap(sInstancesProjectionMap);
break;

case INSTANCE_ID:
qb.setProjectionMap(sInstancesProjectionMap);
qb.appendWhere(InstanceColumns._ID + "=" + uri.getPathSegments().get(1));
break;

Expand Down Expand Up @@ -308,11 +308,21 @@ public int delete(@NonNull Uri uri, String where, String[] whereArgs) {
cv.put(InstanceColumns.DELETED_DATE, System.currentTimeMillis());
count = Collect.getInstance().getContentResolver().update(uri, cv, null, null);
} else {
String[] newWhereArgs;
if (whereArgs == null || whereArgs.length == 0) {
newWhereArgs = new String[] {instanceId};
} else {
newWhereArgs = new String[(whereArgs.length + 1)];
newWhereArgs[0] = instanceId;
System.arraycopy(whereArgs, 0, newWhereArgs, 1, whereArgs.length);
}

count =
db.delete(INSTANCES_TABLE_NAME,
InstanceColumns._ID + "=" + instanceId
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""),
whereArgs);
InstanceColumns._ID
+ "=?"
+ (!TextUtils.isEmpty(where) ? " AND ("
+ where + ')' : ""), newWhereArgs);
}
break;

Expand Down Expand Up @@ -372,11 +382,22 @@ public int update(@NonNull Uri uri, ContentValues values, String where, String[]
}
}

String[] newWhereArgs;
if (whereArgs == null || whereArgs.length == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates code above.

newWhereArgs = new String[] {instanceId};
} else {
newWhereArgs = new String[(whereArgs.length + 1)];
newWhereArgs[0] = instanceId;
System.arraycopy(whereArgs, 0, newWhereArgs, 1, whereArgs.length);
}

count =
db.update(INSTANCES_TABLE_NAME, values,
InstanceColumns._ID + "=" + instanceId
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""),
whereArgs);
db.update(INSTANCES_TABLE_NAME,
values,
InstanceColumns._ID
+ "=?"
+ (!TextUtils.isEmpty(where) ? " AND ("
+ where + ')' : ""), newWhereArgs);
break;

default:
Expand Down