diff --git a/configure.ac b/configure.ac index acdd120..fd8497c 100644 --- a/configure.ac +++ b/configure.ac @@ -15,9 +15,8 @@ AC_CONFIG_AUX_DIR([libltdl/config]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_PROG_LIBTOOL -#fix for automake 1.12 -m4_pattern_allow([AM_PROG_AR]) -AM_PROG_AR +# fix for automake 1.11 & 1.12 +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) LDFLAGS="$LDFLAGS -version-info 0:8:0" diff --git a/libmbus.spec b/libmbus.spec new file mode 100644 index 0000000..c126b4d --- /dev/null +++ b/libmbus.spec @@ -0,0 +1,84 @@ +# +# spec file for package libmbus +# +# Copyright (c) 2010-2013, Raditex Control AB +# All rights reserved. +# +# rSCADA +# http://www.rSCADA.se +# info@rscada.se +# + +Summary: Open source M-bus (Meter-Bus) library +Name: libmbus +Version: 0.8.0 +Release: 1 +Source: http://www.rscada.se/public-dist/%{name}-%{version}.tar.gz +URL: http://www.rscada.se/libmbus/ +License: BSD +Vendor: Raditex Control AB +Packager: Stefan Wahren +Group: Development/Languages/C and C++ +BuildRoot: {_tmppath}/%{name}-%{version}-build +AutoReqProv: on + +%description +libmbus: M-bus Library from Raditex Control (http://www.rscada.se) + +libmbus is an open source library for the M-bus (Meter-Bus) protocol. +The Meter-Bus is a standard for reading out meter data from electricity meters, +heat meters, gas meters, etc. The M-bus standard deals with both the electrical +signals on the M-Bus, and the protocol and data format used in transmissions +on the M-Bus. The role of libmbus is to decode/encode M-bus data, and to handle +the communication with M-Bus devices. + +For more information see http://www.rscada.se/libmbus + +%package devel +License: BSD +Summary: Development libraries and header files for using the M-bus library +Group: Development/Libraries/C and C++ +AutoReqProv: on +Requires: %{name} = %{version} + +%description devel +This package contains all necessary include files and libraries needed +to compile and link applications which use the M-bus (Meter-Bus) library. + +%prep -q +%setup -q +# workaround to get it's build +autoreconf + +%build +./configure --prefix=/usr +make + +%install +rm -Rf "%buildroot" +mkdir "%buildroot" +make install DESTDIR="%buildroot" + +%clean +rm -rf "%buildroot" + +%files +%defattr (-,root,root) +%doc COPYING README +%{_bindir}/mbus-serial-* +%{_bindir}/mbus-tcp-* +%{_libdir}/libmbus.so* +# man pages doesn't exist in this version +# %{_mandir}/man1/libmbus.1 +# %{_mandir}/man1/mbus-* + +%files devel +%defattr (-,root,root) +%{_includedir}/mbus +%{_libdir}/libmbus.a +%{_libdir}/libmbus.la +%{_libdir}/pkgconfig/libmbus.pc + +%changelog +* Fri Mar 29 2013 Stefan Wahren - 0.8.0-1 +- Initial package based on the last official release \ No newline at end of file diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index 0480930..b09a643 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1146,6 +1146,13 @@ mbus_parse_fixed_record(char status_byte, char medium_unit, u_char *data) /* shared/static memory - get own copy */ record->function_medium = strdup(mbus_data_fixed_function((int)status_byte)); /* stored / actual */ + + if (record->function_medium == NULL) + { + MBUS_ERROR("%s: memory allocation error\n", __PRETTY_FUNCTION__); + mbus_record_free(record); + return NULL; + } long value = 0; if ((status_byte & MBUS_DATA_FIXED_STATUS_FORMAT_MASK) == MBUS_DATA_FIXED_STATUS_FORMAT_BCD) @@ -1202,6 +1209,13 @@ mbus_parse_variable_record(mbus_data_record *data) { record->function_medium = strdup("Manufacturer specific"); } + + if (record->function_medium == NULL) + { + MBUS_ERROR("%s: memory allocation error\n", __PRETTY_FUNCTION__); + mbus_record_free(record); + return NULL; + } /* parsing of data not implemented yet manufacturer specific data structures to end of user data */ @@ -1228,6 +1242,14 @@ mbus_parse_variable_record(mbus_data_record *data) else { record->function_medium = strdup(mbus_data_record_function(data)); + + if (record->function_medium == NULL) + { + MBUS_ERROR("%s: memory allocation error\n", __PRETTY_FUNCTION__); + mbus_record_free(record); + return NULL; + } + MBUS_DEBUG("record->function_medium = %s \n", record->function_medium); if (mbus_variable_value_decode(data, &value_out_real, &value_out_str, &value_out_str_size) != 0) diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index 88cf474..b7d16f7 100755 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -3827,6 +3827,10 @@ mbus_frame_data_new() { return NULL; } + + memset(data, 0, sizeof(mbus_frame_data)); + + data->data_var.data = NULL; data->data_var.record = NULL; return data;