kopia lustrzana https://github.com/weetmuts/wmbusmeters
Fixed memory leak in shell.
rodzic
accdb1c0e9
commit
38c3287f68
8
CHANGES
8
CHANGES
|
@ -1,4 +1,12 @@
|
||||||
|
|
||||||
|
Version 0.8.1: 2019-01-04
|
||||||
|
|
||||||
|
Fixed memory leak in shell invocation.
|
||||||
|
Improved dvparser to properly handle the supercom587 telegrams.
|
||||||
|
(It still does not extract all the data, but the data is properly parsed and chunked.)
|
||||||
|
Added address sanitizer to debug build.
|
||||||
|
Added static analysis check.sh.
|
||||||
|
|
||||||
Version 0.8: 2018-11-29
|
Version 0.8: 2018-11-29
|
||||||
|
|
||||||
Multical21 now reports flow temperature and external temperature.
|
Multical21 now reports flow temperature and external temperature.
|
||||||
|
|
12
Makefile
12
Makefile
|
@ -44,7 +44,7 @@ endif
|
||||||
|
|
||||||
$(shell mkdir -p $(BUILD))
|
$(shell mkdir -p $(BUILD))
|
||||||
|
|
||||||
CXXFLAGS := $(DEBUG_FLAGS) -fPIC -fmessage-length=0 -std=c++11 -Wall -Wno-maybe-uninitialized -Wno-unused-function "-DWMBUSMETERS_VERSION=\"0.8\""
|
CXXFLAGS := $(DEBUG_FLAGS) -fPIC -fmessage-length=0 -std=c++11 -Wall -Wno-maybe-uninitialized -Wno-unused-function "-DWMBUSMETERS_VERSION=\"0.8.1\""
|
||||||
|
|
||||||
$(BUILD)/%.o: %.cc $(wildcard %.h)
|
$(BUILD)/%.o: %.cc $(wildcard %.h)
|
||||||
$(CXX) $(CXXFLAGS) $< -c -o $@
|
$(CXX) $(CXXFLAGS) $< -c -o $@
|
||||||
|
@ -72,20 +72,20 @@ METERS_OBJS:=\
|
||||||
all: $(BUILD)/wmbusmeters $(BUILD)/testinternals
|
all: $(BUILD)/wmbusmeters $(BUILD)/testinternals
|
||||||
@$(STRIP_BINARY)
|
@$(STRIP_BINARY)
|
||||||
|
|
||||||
dist: wmbusmeters_0.8_$(DEBARCH).deb
|
dist: wmbusmeters_0.8.1_$(DEBARCH).deb
|
||||||
|
|
||||||
wmbusmeters_0.8_$(DEBARCH).deb:
|
wmbusmeters_0.8.1_$(DEBARCH).deb:
|
||||||
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
|
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
|
||||||
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/local/bin
|
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/local/bin
|
||||||
@cp $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters/usr/local/bin
|
@cp $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters/usr/local/bin
|
||||||
@rm -f $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@rm -f $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@echo "Version: 0.8" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@echo "Version: 0.8.1" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@echo "Maintainer: Fredrik Öhrström" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@echo "Maintainer: Fredrik Öhrström" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@echo "Architecture: $(DEBARCH)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@echo "Architecture: $(DEBARCH)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@echo "Description: A tool to read wireless mbus telegrams from utility meters." >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@echo "Description: A tool to read wireless mbus telegrams from utility meters." >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@(cd $(BUILD)/debian; dpkg-deb --build wmbusmeters .)
|
@(cd $(BUILD)/debian; dpkg-deb --build wmbusmeters .)
|
||||||
@mv $(BUILD)/debian/wmbusmeters_0.8_$(DEBARCH).deb .
|
@mv $(BUILD)/debian/wmbusmeters_0.8.1_$(DEBARCH).deb .
|
||||||
@echo Built package $@
|
@echo Built package $@
|
||||||
|
|
||||||
$(BUILD)/wmbusmeters: $(METERS_OBJS) $(BUILD)/main.o
|
$(BUILD)/wmbusmeters: $(METERS_OBJS) $(BUILD)/main.o
|
||||||
|
@ -96,7 +96,7 @@ $(BUILD)/testinternals: $(METERS_OBJS) $(BUILD)/testinternals.o
|
||||||
$(CXX) -o $(BUILD)/testinternals $(METERS_OBJS) $(BUILD)/testinternals.o $(DEBUG_LDFLAGS) -lpthread
|
$(CXX) -o $(BUILD)/testinternals $(METERS_OBJS) $(BUILD)/testinternals.o $(DEBUG_LDFLAGS) -lpthread
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f build/* build_arm/* build_debug/* build_arm_debug/* *~
|
rm -rf build/* build_arm/* build_debug/* build_arm_debug/* *~
|
||||||
|
|
||||||
test:
|
test:
|
||||||
./build/testinternals
|
./build/testinternals
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Build with static analysis tool Coverity
|
||||||
|
make clean
|
||||||
|
rm -rf cov-int
|
||||||
|
cov-build --dir cov-int make
|
||||||
|
tar czvf wmbusmeters.tgz cov-int
|
|
@ -80,8 +80,8 @@ struct SerialDeviceTTY : public SerialDeviceImp {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
string device_;
|
string device_;
|
||||||
int baud_rate_;
|
int baud_rate_ {};
|
||||||
int fd_;
|
int fd_ {};
|
||||||
pthread_mutex_t write_lock_ = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t write_lock_ = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_mutex_t read_lock_ = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t read_lock_ = PTHREAD_MUTEX_INITIALIZER;
|
||||||
SerialCommunicationManagerImp *manager_;
|
SerialCommunicationManagerImp *manager_;
|
||||||
|
@ -208,6 +208,9 @@ unique_ptr<SerialDevice> SerialCommunicationManagerImp::createSerialDeviceTTY(st
|
||||||
|
|
||||||
void SerialCommunicationManagerImp::listenTo(SerialDevice *sd, function<void()> cb) {
|
void SerialCommunicationManagerImp::listenTo(SerialDevice *sd, function<void()> cb) {
|
||||||
SerialDeviceImp *si = dynamic_cast<SerialDeviceImp*>(sd);
|
SerialDeviceImp *si = dynamic_cast<SerialDeviceImp*>(sd);
|
||||||
|
if (!si) {
|
||||||
|
error("Internal error: Invalid serial device passed to listenTo.\n");
|
||||||
|
}
|
||||||
si->on_data_ = cb;
|
si->on_data_ = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
serial.h
1
serial.h
|
@ -36,6 +36,7 @@ struct SerialDevice {
|
||||||
virtual int receive(std::vector<uchar> *data) = 0;
|
virtual int receive(std::vector<uchar> *data) = 0;
|
||||||
virtual int fd() = 0;
|
virtual int fd() = 0;
|
||||||
virtual SerialCommunicationManager *manager() = 0;
|
virtual SerialCommunicationManager *manager() = 0;
|
||||||
|
virtual ~SerialDevice() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SerialCommunicationManager {
|
struct SerialCommunicationManager {
|
||||||
|
|
6
shell.cc
6
shell.cc
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
void invokeShell(string program, vector<string> args, vector<string> envs)
|
void invokeShell(string program, vector<string> args, vector<string> envs)
|
||||||
{
|
{
|
||||||
const char **argv = new const char*[args.size()+2];
|
vector<const char*> argv(args.size()+2);
|
||||||
argv[0] = program.c_str();
|
argv[0] = program.c_str();
|
||||||
int i = 1;
|
int i = 1;
|
||||||
debug("exec \"%s\"\n", program.c_str());
|
debug("exec \"%s\"\n", program.c_str());
|
||||||
|
@ -38,7 +38,7 @@ void invokeShell(string program, vector<string> args, vector<string> envs)
|
||||||
}
|
}
|
||||||
argv[i] = NULL;
|
argv[i] = NULL;
|
||||||
|
|
||||||
const char **env = new const char*[envs.size()+1];
|
vector<const char*> env(envs.size()+1);
|
||||||
env[0] = program.c_str();
|
env[0] = program.c_str();
|
||||||
i = 0;
|
i = 0;
|
||||||
for (auto &e : envs) {
|
for (auto &e : envs) {
|
||||||
|
@ -53,7 +53,7 @@ void invokeShell(string program, vector<string> args, vector<string> envs)
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
// I am the child!
|
// I am the child!
|
||||||
close(0); // Close stdin
|
close(0); // Close stdin
|
||||||
execvpe(program.c_str(), (char*const*)argv, (char*const*)env);
|
execvpe(program.c_str(), (char*const*)&argv[0], (char*const*)&env[0]);
|
||||||
perror("Execvp failed:");
|
perror("Execvp failed:");
|
||||||
error("Invoking shell %s failed!\n", program.c_str());
|
error("Invoking shell %s failed!\n", program.c_str());
|
||||||
} else {
|
} else {
|
||||||
|
|
14
test.sh
14
test.sh
|
@ -43,3 +43,17 @@ then
|
||||||
else
|
else
|
||||||
Failure.
|
Failure.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
$PROG --shell='echo "$METER_JSON"' simulation_shell.txt MWW supercom587 12345678 "" > test_output.txt
|
||||||
|
if [ "$?" == "0" ]
|
||||||
|
then
|
||||||
|
cat test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > test_responses.txt
|
||||||
|
echo '{"media":"warm water","meter":"supercom587","name":"MWW","id":"12345678","total_m3":5.548000,"timestamp":"1111-11-11T11:11:11Z"}' > test_expected.txt
|
||||||
|
diff test_expected.txt test_responses.txt
|
||||||
|
if [ "$?" == "0" ]
|
||||||
|
then
|
||||||
|
echo SHELL OK
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
Failure.
|
||||||
|
fi
|
||||||
|
|
5
wmbus.cc
5
wmbus.cc
|
@ -655,7 +655,6 @@ string vifType(int vif)
|
||||||
|
|
||||||
case 0x78: return "Fabrication no";
|
case 0x78: return "Fabrication no";
|
||||||
case 0x79: return "Enhanced identification";
|
case 0x79: return "Enhanced identification";
|
||||||
case 0x80: return "Address";
|
|
||||||
|
|
||||||
case 0x7C: return "VIF in following string (length in first byte)";
|
case 0x7C: return "VIF in following string (length in first byte)";
|
||||||
case 0x7E: return "Any VIF";
|
case 0x7E: return "Any VIF";
|
||||||
|
@ -988,7 +987,6 @@ string vifKey(int vif)
|
||||||
|
|
||||||
case 0x78: return "fabrication_no"; // Fabrication no
|
case 0x78: return "fabrication_no"; // Fabrication no
|
||||||
case 0x79: return "enhanced_identification"; // Enhanced identification
|
case 0x79: return "enhanced_identification"; // Enhanced identification
|
||||||
case 0x80: return "address"; // Address
|
|
||||||
|
|
||||||
case 0x7C: // VIF in following string (length in first byte)
|
case 0x7C: // VIF in following string (length in first byte)
|
||||||
case 0x7E: // Any VIF
|
case 0x7E: // Any VIF
|
||||||
|
@ -1146,7 +1144,6 @@ string vifUnit(int vif)
|
||||||
|
|
||||||
case 0x78: return ""; // Fabrication no
|
case 0x78: return ""; // Fabrication no
|
||||||
case 0x79: return ""; // Enhanced identification
|
case 0x79: return ""; // Enhanced identification
|
||||||
case 0x80: return ""; // Address
|
|
||||||
|
|
||||||
case 0x7C: // VIF in following string (length in first byte)
|
case 0x7C: // VIF in following string (length in first byte)
|
||||||
case 0x7E: // Any VIF
|
case 0x7E: // Any VIF
|
||||||
|
@ -1530,7 +1527,7 @@ string vif_FB_ExtensionType(uchar dif, uchar vif, uchar vife)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((vife & 0x7e) == 0x29 ||
|
if ((vife & 0x7f) == 0x29 ||
|
||||||
(vife & 0x7c) == 0x2c) {
|
(vife & 0x7c) == 0x2c) {
|
||||||
return "Reserved";
|
return "Reserved";
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ private:
|
||||||
vector<uchar> read_buffer_;
|
vector<uchar> read_buffer_;
|
||||||
pthread_mutex_t command_lock_ = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t command_lock_ = PTHREAD_MUTEX_INITIALIZER;
|
||||||
sem_t command_wait_;
|
sem_t command_wait_;
|
||||||
int sent_command_;
|
int sent_command_ {};
|
||||||
int received_command_;
|
int received_command_ {};
|
||||||
vector<uchar> received_payload_;
|
vector<uchar> received_payload_;
|
||||||
vector<function<void(Telegram*)>> telegram_listeners_;
|
vector<function<void(Telegram*)>> telegram_listeners_;
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ private:
|
||||||
vector<function<void(Telegram*)>> telegram_listeners_;
|
vector<function<void(Telegram*)>> telegram_listeners_;
|
||||||
|
|
||||||
string file_;
|
string file_;
|
||||||
SerialCommunicationManager *manager_;
|
SerialCommunicationManager *manager_ {};
|
||||||
LinkMode link_mode_;
|
LinkMode link_mode_ {};
|
||||||
vector<string> lines_;
|
vector<string> lines_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -120,14 +120,13 @@ void decryptMode5_AES_CBC(Telegram *t, vector<uchar> &aeskey)
|
||||||
|
|
||||||
uchar decrypted_data[content.size()];
|
uchar decrypted_data[content.size()];
|
||||||
AES_CBC_decrypt_buffer(decrypted_data, &content[0], content.size(), &aeskey[0], iv);
|
AES_CBC_decrypt_buffer(decrypted_data, &content[0], content.size(), &aeskey[0], iv);
|
||||||
vector<uchar> decrypted(decrypted_data, decrypted_data+content.size());
|
|
||||||
|
|
||||||
if (decrypted_data[0] != 0x2F || decrypted_data[1] != 0x2F) {
|
if (decrypted_data[0] != 0x2F || decrypted_data[1] != 0x2F) {
|
||||||
verbose("(Mode5) decrypt failed!\n");
|
verbose("(Mode5) decrypt failed!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
t->content.clear();
|
t->content.clear();
|
||||||
t->content.insert(t->content.end(), decrypted.begin(), decrypted.end());
|
t->content.insert(t->content.end(), decrypted_data, decrypted_data+content.size());
|
||||||
debugPayload("(Mode5) decrypted", t->content);
|
debugPayload("(Mode5) decrypted", t->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue