Reviewed By: jeremydubreil Differential Revision: D12942819 fbshipit-source-id: c294b4238master
parent
141d0da672
commit
174bdcd22b
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package codetoanalyze.java.quandary;
|
||||
|
||||
import android.content.ClipboardManager;
|
||||
|
||||
public class ClassLoading {
|
||||
ClipboardManager clipboard;
|
||||
|
||||
public String getUserControlledString() {
|
||||
return this.clipboard.getText().toString();
|
||||
}
|
||||
|
||||
public void clipboardToClassForNameBad() {
|
||||
try {
|
||||
Class cls = Class.forName(this.getUserControlledString());
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
We don't want to report it as we consider that string concatenation
|
||||
sanitizes the user-controlled string for class loading.
|
||||
*/
|
||||
public void FP_clipboardToClassForNameWithConcatenationGood() {
|
||||
String javaFileName = "blabla." + this.getUserControlledString();
|
||||
try {
|
||||
Class cls = Class.forName(javaFileName);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue