Skip to content

Commit 67d6474

Browse files
authored
Merge pull request #218 from exexute/main
Fix: codeql notify
2 parents ed0c876 + d93bc31 commit 67d6474

File tree

13 files changed

+28
-20
lines changed

13 files changed

+28
-20
lines changed

dongtai-servlet-api/src/main/java/cn/huoxian/iast/api/HttpRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ private static String getPostBody(HttpServletRequest request) {
7171
while ((str = reader.readLine()) != null) {
7272
postBody.append(str);
7373
}
74+
inputStream.close();
75+
reader.close();
7476
return postBody.toString();
7577
} else {
7678
request.setCharacterEncoding("UTF-8");

iast-agent/src/main/java/com/secnium/iast/agent/IastClassLoader.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class IastClassLoader extends URLClassLoader {
2222
private final String path;
2323

2424
public IastClassLoader(final String namespace,
25-
final String jarFilePath) throws MalformedURLException {
25+
final String jarFilePath) throws MalformedURLException {
2626
super(new URL[]{new URL("file:" + jarFilePath)});
2727
this.path = jarFilePath;
2828
this.toString = String.format("IastClassLoader[namespace=%s;path=%s;]", namespace, path);
@@ -55,7 +55,6 @@ protected synchronized Class<?> loadClass(String name, boolean resolve) throws C
5555
return loadedClass;
5656
}
5757

58-
5958
try {
6059
Class<?> aClass = findClass(name);
6160
if (resolve) {
@@ -75,7 +74,7 @@ public String toString() {
7574

7675
@SuppressWarnings("unused")
7776
public void closeIfPossible() {
78-
77+
// JDK6版本的 URLClassLoader 未继承Closeable接口,无法自动关闭,需要手动释放
7978
if (this instanceof Closeable) {
8079
try {
8180
((Closeable) this).close();
@@ -84,17 +83,18 @@ public void closeIfPossible() {
8483
return;
8584
}
8685

87-
8886
// 对于JDK6的版本,URLClassLoader要关闭起来就显得有点麻烦,这里弄了一大段代码来稍微处理下
8987
// 而且还不能保证一定释放干净了,至少释放JAR文件句柄是没有什么问题了
9088
try {
9189
final Object sun_misc_URLClassPath = forceGetDeclaredFieldValue(URLClassLoader.class, "ucp", this);
92-
final Object java_util_Collection = forceGetDeclaredFieldValue(sun_misc_URLClassPath.getClass(), "loaders", sun_misc_URLClassPath);
90+
final Object java_util_Collection = forceGetDeclaredFieldValue(sun_misc_URLClassPath.getClass(), "loaders",
91+
sun_misc_URLClassPath);
9392

9493
for (final Object sun_misc_URLClassPath_JarLoader :
9594
((Collection) java_util_Collection).toArray()) {
9695
try {
97-
final JarFile java_util_jar_JarFile = forceGetDeclaredFieldValue(sun_misc_URLClassPath_JarLoader.getClass(), "jar", sun_misc_URLClassPath_JarLoader);
96+
final JarFile java_util_jar_JarFile = forceGetDeclaredFieldValue(
97+
sun_misc_URLClassPath_JarLoader.getClass(), "jar", sun_misc_URLClassPath_JarLoader);
9898
java_util_jar_JarFile.close();
9999
} catch (Throwable t) {
100100
// if we got this far, this is probably not a JAR loader so skip it
@@ -107,7 +107,8 @@ public void closeIfPossible() {
107107

108108
}
109109

110-
private <T> T forceGetDeclaredFieldValue(Class<?> clazz, String name, Object target) throws NoSuchFieldException, IllegalAccessException {
110+
private <T> T forceGetDeclaredFieldValue(Class<?> clazz, String name, Object target)
111+
throws NoSuchFieldException, IllegalAccessException {
111112
final Field field = clazz.getDeclaredField(name);
112113
field.setAccessible(true);
113114
return (T) field.get(target);

iast-agent/src/main/java/com/secnium/iast/agent/manager/EngineManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ private boolean downloadJarPackageToCacheFromUrl(String fileUrl, String fileName
143143
fileOutputStream.write(dataBuffer, 0, bytesRead);
144144
}
145145
DongTaiLog.info("The remote file " + fileUrl + " was successfully written to the local cache.");
146+
fileOutputStream.close();
146147
status = true;
147148
} catch (Exception ignore) {
148149
DongTaiLog.error("The remote file " + fileUrl + " download failure, please check the iast-token.");

iast-agent/src/main/java/com/secnium/iast/agent/util/http/HttpClientUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class HttpClientUtils {
3434
private final static IastProperties PROPERTIES = IastProperties.getInstance();
3535
private final static Proxy PROXY = loadProxy();
3636

37-
// private static final Logger logger = LogUtils.getLogger(HttpClientUtils.class);
3837

3938
public static StringBuilder sendGet(String uri, String arg, String value) {
4039
try {
@@ -73,8 +72,8 @@ private static StringBuilder sendRequest(HttpMethods method, String baseUrl, Str
7372
connection = proxy == null ? (HttpURLConnection) url.openConnection()
7473
: (HttpURLConnection) url.openConnection(proxy);
7574
}
76-
connection.setReadTimeout(10*1000);
77-
connection.setConnectTimeout(10*1000);
75+
connection.setReadTimeout(10 * 1000);
76+
connection.setConnectTimeout(10 * 1000);
7877

7978
connection.setRequestMethod(method.name());
8079
if (HttpMethods.POST.equals(method)) {

iast-core/src/main/java/com/secnium/iast/core/PropertyUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ private void init() {
5757
File propertiesFile = new File(propertiesFilePath);
5858
if (propertiesFile.exists()) {
5959
cfg = new Properties();
60-
cfg.load(new FileInputStream(propertiesFile));
60+
FileInputStream fis = new FileInputStream(propertiesFile);
61+
cfg.load(fis);
62+
fis.close();
6163
}
6264
} catch (FileNotFoundException e) {
6365
e.printStackTrace();

iast-core/src/main/java/com/secnium/iast/core/enhance/IastClassAncestorQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public synchronized void saveAncestors(String className, String superName, Strin
6666
* @param interfaces 当前类实现的接口列表
6767
* @return 当前类的类族
6868
*/
69-
public synchronized HashSet<String> getAncestors(String className, String superClassName, String[] interfaces) {
70-
HashSet<String> ancestors = (HashSet<String>) this.classAncestorMap.get(className);
69+
public synchronized Set<String> getAncestors(String className, String superClassName, String[] interfaces) {
70+
Set<String> ancestors = this.classAncestorMap.get(className);
7171

7272
if (!isNullOrEmpty(superClassName) && !BASE_CLASS.equals(superClassName)) {
7373
addClassToAncestor(superClassName, ancestors);

iast-core/src/main/java/com/secnium/iast/core/enhance/IastClassFileTransformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashSet;
2424
import java.util.List;
2525

26+
import java.util.Set;
2627
import org.apache.commons.lang3.time.StopWatch;
2728
import org.objectweb.asm.ClassReader;
2829
import org.objectweb.asm.ClassVisitor;
@@ -102,7 +103,7 @@ public byte[] transform(final ClassLoader loader,
102103
final String className = cr.getClassName();
103104
COMMON_UTILS.setLoader(loader);
104105
COMMON_UTILS.saveAncestors(className, superName, interfaces);
105-
HashSet<String> ancestors = COMMON_UTILS.getAncestors(className, superName, interfaces);
106+
Set<String> ancestors = COMMON_UTILS.getAncestors(className, superName, interfaces);
106107

107108
final ClassWriter cw = createClassWriter(loader, cr);
108109
ClassVisitor cv = plugins.initial(cw, IastContext.build(className, ancestors, interfaces,

iast-core/src/main/java/com/secnium/iast/core/enhance/sca/ScaScanner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public InputStream getJarInputStream(String filePath, String name) throws Except
133133
public void scanClassPath(String packagesPath) {
134134
String osName = System.getProperty("os.name").toLowerCase();
135135
String[] packages;
136-
if (osName.contains("windows")){
136+
if (osName.contains("windows")) {
137137
packages = packagesPath.split(";");
138-
}else {
138+
} else {
139139
packages = packagesPath.split(":");
140140
}
141141
for (String packagePath : packages) {
@@ -165,6 +165,7 @@ private void scanJarLib(String packagePath) {
165165
try {
166166
JarFile file = new JarFile(packagePath);
167167
Enumeration<JarEntry> entries = file.entries();
168+
file.close();
168169
String entryName;
169170
while (entries.hasMoreElements()) {
170171
JarEntry entry = entries.nextElement();

iast-core/src/main/java/com/secnium/iast/core/handler/vulscan/normal/CookieFlagsMissingVulScan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void scan(IastSinkModel sink, MethodEvent event) {
1515
Asserts.NOT_NULL("sink.params.position", sink.getPos());
1616
Asserts.NOT_NULL("sink.params.value", event.argumentArray);
1717

18-
for (Integer pos : taintPos) {
18+
for (int pos : taintPos) {
1919
try {
2020
Boolean flag = (Boolean) arguments[pos];
2121
if (flag) {

iast-core/src/main/java/com/secnium/iast/core/handler/vulscan/normal/CryptoBacCiphersVulScan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void scan(IastSinkModel sink, MethodEvent event) {
2323
Asserts.NOT_NULL("sink.params.value", arguments);
2424

2525
Matcher matcher;
26-
for (Integer pos : taintPos) {
26+
for (int pos : taintPos) {
2727
try {
2828
matcher = GOOD_CIPHERS.matcher((CharSequence) arguments[pos]);
2929
if (matcher.find()) {

0 commit comments

Comments
 (0)