Skip to content

Commit

Permalink
Update HydraLabVpnLoggerTemp.kt and disable the network scanner funct…
Browse files Browse the repository at this point in the history
…ion to resolve CodeQL issue (#670)

<!-- Please provide brief information about the PR, what it contains &
its purpose, new behaviors after the change. And let us know here if you
need any help: https://github.com/microsoft/HydraLab/issues/new -->

## Description

Update HydraLabVpnLoggerTemp.kt and disable the network scanner function
to resolve CodeQL issue: Uncontrolled data used in path expression

### Linked GitHub issue ID: #  

## Pull Request Checklist
<!-- Put an x in the boxes that apply. This is simply a reminder of what
we are going to look for before merging your code. -->

- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Code compiles correctly with all tests are passed.
- [ ] I've read the [contributing
guide](https://github.com/microsoft/HydraLab/blob/main/CONTRIBUTING.md#making-changes-to-the-code)
and followed the recommended practices.
- [ ] [Wikis](https://github.com/microsoft/HydraLab/wiki) or
[README](https://github.com/microsoft/HydraLab/blob/main/README.md) have
been reviewed and added / updated if needed (for bug fixes / features)

### Does this introduce a breaking change?
*If this introduces a breaking change for Hydra Lab users, please
describe the impact and migration path.*

- [ ] Yes
- [x] No

## How you tested it
*Please make sure the change is tested, you can test it by adding UTs,
do local test and share the screenshots, etc.*


Please check the type of change your PR introduces:
- [x] Bugfix
- [ ] Feature
- [ ] Technical design
- [ ] Build related changes
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Code style update (formatting, renaming) or Documentation content
changes
- [ ] Other (please describe): 

### Feature UI screenshots or Technical design diagrams
*If this is a relatively large or complex change, kick it off by drawing
the tech design with PlantUML and explaining why you chose the solution
you did and what alternatives you considered, etc...*
  • Loading branch information
hydraxman authored Jan 7, 2025
1 parent 2043c5a commit 73a2727
Showing 1 changed file with 2 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@ class HydraLabVpnLoggerTemp(private var filePath: String?) {
private var lines = mutableListOf<String>()
private var linesStaging = listOf<String>()

init {
if (filePath != null) {
filePath = Environment.getExternalStorageDirectory().toString() + filePath

val publicFolder = Path(Environment.getExternalStorageDirectory().toString()).toString()
val fileUrl = Path(filePath.toString()).toString()
if (!fileUrl.startsWith(publicFolder + File.separator)) {
throw IllegalArgumentException("Invalid file path")
}

val file = File(fileUrl ?: "")
if (file.exists()) {
file.writeText("")
} else {
file.createNewFile()
}
}
}

fun stringify(packet: Packet): String {
return packet.toString()
Expand All @@ -42,29 +24,10 @@ class HydraLabVpnLoggerTemp(private var filePath: String?) {
}

private fun log(line: String) {
lines.add(line)
if (lines.size >= 100) {
flush()
}

}

fun flush() {
linesStaging = lines.toList()
lines.clear()
if (filePath == null) {
return
}
GlobalScope.launch(Dispatchers.IO) {
try {
FileWriter(filePath, true).use { writer ->
for (line in linesStaging) {
writer.write(line)
writer.write("\n")
}
}
} catch (e: IOException) {
e.printStackTrace()
}
}

}
}

0 comments on commit 73a2727

Please sign in to comment.