Skip to content

Commit

Permalink
Fix a soft-crash when the raw hcidump line is invalid and cuts out in…
Browse files Browse the repository at this point in the history
… the middle of the MAC address and improve logging
  • Loading branch information
Scrin committed Apr 30, 2019
1 parent 98f1f27 commit 5270037
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### v0.2.4

- Significant amount of refactoring, this release may be a bit more unstable than usual
- Added "defaultWithMotionSensitivity" limiting strategy (see ruuvi-collector.properties.example for configuration details, thanks ZeroOne3010)
- Updated various dependencies and added [ruuvitag-common-java](https://github.com/Scrin/ruuvitag-common-java) as a dependency
- Added tests (thanks ZeroOne3010)
- Fixed a rare soft-crash when the raw hcidump line is invalid and cuts out in the middle of the MAC address

### v0.2.3

- Added advanced configuration options for InfluxDB
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/fi/tkgwf/ruuvi/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static void main(String[] args) {
} else {
Main m = new Main();
if (!m.run()) {
LOG.info("Unclean exit");
System.exit(1);
}
}
Expand Down Expand Up @@ -88,9 +89,14 @@ boolean run(final BufferedReader reader) {
HCIData hciData = parser.readLine(line);
if (hciData != null) {
beaconHandler.handle(hciData).map(MeasurementValueCalculator::calculateAllValues).ifPresent(persistenceService::store);
latestMAC = null; // "reset" the mac to null to avoid misleading MAC addresses when an error happens *after* successfully reading a full packet
}
} catch (Exception ex) {
LOG.warn("Uncaught exception while handling measurements from MAC address \"" + latestMAC + "\", if this repeats and this is not a Ruuvitag, consider blacklisting it", ex);
if (latestMAC != null) {
LOG.warn("Uncaught exception while handling measurements from MAC address \"" + latestMAC + "\", if this repeats and this is not a Ruuvitag, try blacklisting it", ex);
} else {
LOG.warn("Uncaught exception while handling measurements, this is an unexpected event. Please report this to https://github.com/Scrin/RuuviCollector/issues and include this log", ex);
}
LOG.debug("Offending line: " + line);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/fi/tkgwf/ruuvi/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public static String getMacFromLine(String line) {
if (StringUtils.isBlank(line)) {
return null;
}
StringBuilder sb = new StringBuilder();
String[] split = line.split(" ", 7); // 6 blocks plus remaining garbage
if (split.length < 6) {
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 5; i >= 0; i--) {
sb.append(split[i]);
}
Expand Down

0 comments on commit 5270037

Please sign in to comment.