Skip to content

Commit e285726

Browse files
okurtsevstephanejoboltimgates42anton-bondarev
authored
Update libmodbus to address CVE-2022-0367 (#3)
* Move malloc before starting unit tests * Fix warning issues When compiling with gcc and option -Wconversion it fixes the warning message warning: conversion from ‘X’ {aka ‘x’} to ‘Y’ {aka ‘y’} may change value Signed-off-by: José Bollo <[email protected]> * Add modbus_[get|set]_indication_timeout to doc build * docs: fix simple typo, reponse -> response There is a small typo in tests/bandwidth-client.c. Should read `response` rather than `reponse`. * Update README.md Add Embox RTOS to the list of supported OSes * Install the NEWS and AUTHORS files Fix stephane#513 * Include the test LICENSE in tarball Fix for stephane#542 * Add .clabot * typo * Replace .dir-locals.el (Emacs) by .editorconfig * Fix many typos Thanks to @peternewman * cosmetic changes in man page standardizing itemization * Add FUNDING.yml * Add the baud rate of 256k for Windows (closes stephane#603) * Remove duplicate ';' (closes stephane#602) * Fix position of CC flags in documentation (closes stephane#599) * Replace obsolete AC_PROG_CC_STDC by AC_PROG_CC * Fix typo in comment (closes stephane#588) Thank you @qqq89513 * Add SECURITY.md (closes stephane#613) * modbus_reply: fix copy & paste error in sanity check (fixes stephane#614) While handling MODBUS_FC_WRITE_AND_READ_REGISTERS, both address offsets must be checked, i.e. the read and the write address must be within the mapping range. At the moment, only the read address was considered, it looks like a simple copy and paste error, so let's fix it. Signed-off-by: Michael Heimpold <[email protected]> * Bump version to 3.1.7 * Minor changes to NEWS * Fix typos (closes stephane#620) * Add many contributors to .clabot * Minor documentation correction Sorry for the two PRs, I did one then realized I should check the other * Minor documentation correction * Fix network library detection on Haiku * Fix typo on connection (closes stephane#586). Thank you @peternewman. * Add rm5248 to .clabot * Fix comment about EMBUNKEXC (closes stephane#566) This native libmodbus error code is defined but not used. * Fix float endianness issue on big endian architecture. It converts float values depending on what order they come in. This patch was modified from rm5248 [1] [1] synexxus@a511768 * Make sub-command more clear * Swap CRC bytes in request data but not at CRC computing (stephane#397) * address check in single register / coil responses added (stephane#463) Address check in single register / coil responses added According to Modbus standard the address of single register / coils request and response must match Co-authored-by: Heinrich Gsponer <[email protected]> * Add contributors to .clabot * VCLinkerTool version 1.0.0 to 1.0, NO link error Even the newest visual studio use /VERSION:major[.minor] . It means link.exe /VERSION:1.0 just need two version number . If Version = 1.0.0 , when visual studio link the program , vs will produce link error: ``` 1>"/OUT:C:\Users\Lenovo\Desktop\libmodbus-master\src\win32\modbus.dll" "/VERSION:1.0.0" /INCREMENTAL:NO /NOLOGO ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG "/PDB:C:\Users\Lenovo\Desktop\libmodbus-master\src\win32\modbus.pdb" /MAP /SUBSYSTEM:CONSOLE /TLBID:1 "/IMPLIB:C:\Users\Lenovo\Desktop\libmodbus-master\src\win32\modbus.lib" /MACHINE:X86 /SAFESEH /DLL "C:\Users\Lenovo\Desktop\libmodbus-master\src\win32\/modbus.res" 1>"Debug\modbus-data.obj" 1>"Debug\modbus-rtu.obj" 1>"Debug\modbus-tcp.obj" 1>Debug\modbus.obj 1>LINK : fatal error LNK1117: option“VERSION:1.0.0” grammatical error ``` see: https://docs.microsoft.com/en-us/cpp/build/reference/version-version-information?view=msvc-160 * Add jcarrano to CLA * Update .gitignore * Add build check to CI * Add autogen.sh call * Remove check target (duplicate of distcheck) * Replace Travis CI badge by GitHub CI * Merge NEWS with v3.0.x branch * Fixed MODBUS_ERROR_RECOVERY_LINK not working on Windows. * Fixed a typo error in a comment. * Do not change the behavior for non-windows OS. * Reduce memory use of TCP PI backend (closes stephane#621) - allocate exact memory required to store node and service strings instead of around 1kb of static memory. - accept NULL value of service to use default Modbus port number (502) - unit test updated The new documentation will be updated in another commit. * Rewrite documentation with Material for mkdocs - remove doc build from autotools - don't depend anymore on asciidoc - don't provide man pages anymore - new illustrations - provide mkdocs instructions * Bump version to 3.1.8 * Remove travis.yml * Minor adjustments to MD files * Remove year range in Copyright * Move migration content to libmodbus.org * Avoid negative value in FD_SET call * Test socket against positive value instead of -1 * Add 0x34d to .clabot * Add jordanjohnson56 to CLA * Have autogen.sh fail if autoreconf fails If the autoreconf program does not succeed, autogen.sh should not succeed either. The definition of "succeed" being "exit with exit code 0". * Have autoreconf fail if LT_INIT is not defined If the LT_INIT macro is not available in a *.m4 file to be found during the autoreconf run, it is impossible to build a useful configure script. Therefore, we blacklist the LT_INIT macro so when it appears unexpanded in the configure script, autoreconf will report the failure instead of silently creating a broken configure. This is generally a good idea for any macro not shipped with Automake or Autoconf. * Fix doc links * test the protocol id for 0 previous test would fail if one byte was non zero. * Fix double negative in tests * New quirks handler (closes stephane#38 stephane#533) Useful functions when you are confronted with equipment which does not respect the protocol, which behaves strangely or when you wish to move away from the standard. Thank you @mhei for the great initial version. * Fix bitwise OR in documentation * Improve doc about slave ID in RTU * Add .clang-format and format code (closes stephane#394) Thank you @pboettch for initial proposal. * Remove constraints on baud rate values * Accept IP or device in arg of unit test progs * Avoid compilation issue with VS2022 with strdup * Display created files in configure.js * Use strcpy_s under Windows * Replace inet_addr by inet_pton calls * Replace inet_ntoa by inet_ptop - check conversion - display IP in in IPv6 * Update configure.ac/config.h.win32 for new inet functions * Instructions to build libmodbus in a VS project Tested with Visual Studio 2022. * Updated CLA bot file * Fix connection check for Windows RTU (closes stephane#660, stephane#662) * Add CIFuzz Github action * Convert a few int to unsigned int (stephane#402) * Fix wrong close on recent commit 5a6efec * Adjust fuzzing to run on main branch only * Bump version to 3.1.9 * fix modbus quirks function definition * Split POSIX and Windows RTU connect functions Easier to read * Fix setting baud rate for Linux (partial revert of fa20798) * Remove fuzzing action in waiting for a fix * Bump version to 3.1.10 * docs: small re-wordings, fix various small typos and style issues Signed-off-by: Michael Heimpold <[email protected]> * Update CLA * Fix doc of modbus_mapping_new_start_address (stephane#615) * Free addrinfo struct on getaddrinfo() errors * Minor to docs * Add polar.sh to FUNDING * Fix errno value on timeout with TCP connect (closes stephane#736, stephane#756) Thank you kyllingstad for the issue and psychon for the fix. * Update CLA * Log error in read input registers if debug (closes stephane#755) * Add checks for netinet/ip.h and gai_strerror Extracted from stephane#745 * Don't use gai_strerror if not available Identical check to stephane#745 * stephane#675 fix wrong generated version for double number * adding modbus_send_raw_request_tid * doc * doc * Don't use loop initial declaration (closes stephane#752) C99 remains too modern :/ * Minor format * Update docs about memory consumption (closes stephane#715) Not true anymore since stephane#621 * Revert TCP checks for recovery (closes stephane#711) Requires more tests on Windows with serial communications... Related to db1cbc5 and 9b679b7. * Link against socket and nsl libs when building on SunOS On OpenIndiana (SunOS) functions such as bind, socket, listen require -lnsl -lsocket to be given to linker. * Format * Fixes float encoding/decoding for both big and little endian (fixes stephane#665, stephane#694) * Removes useless memcpy calls and no longer used swap32 and swap16 macros. * Updated float encoding functions to consider endianess of 16-bit registers (fixes stephane#665) * Deprecated modbus_get_float() and modbus_set_float() are implemented using cdab variants. * Duplicate in .clabot * Revert "Fixes float encoding/decoding for both big and little endian (fixes stephane#665, stephane#694)" This reverts commit 13bd584. * Remove useless cast in setsockopt call (closes stephane#721) * Update CLA * Fix insecure data handling CID 416366: INTEGER_OVERFLOW found with Coverity Scan. * Add Coverity scan status * Remove duplicate warning flag * Check length passed to modbus_reply (write_bit) The modbus_reply function is designed to receive arguments from modbus_receive. This patch avoid a wrong use of memcpy if the user chooses to inject a bad length argument. Thank you Nozomi Networks Labs Advisory for the report. * Check length passed to modbus_reply (write_register) Related to df79a02. * Small cleanups of unit test server * Rename warning flags variable * Do not build with debug flag active by default * Remove useless configure checks * Update .clabot * Fix request length check in modbus_reply in RTU - rename internal *_prepare_response_tid to *_get_response_tid - change signature, don't need req length anymore - remove misleading modification of req_length - check of req length before use in memcpy for mask write register Related to df79a02 * Revert "Fix float endianness issue on big endian architecture." and fix test suite and setter functions. This reverts commit 49af73d. * Prepare NEWS file for next release * Use port 502 instead of 1502 in documentation (closes stephane#771) The default port number of Modbus is 502 but it requires privileges on Linux. * HAVE_NETINET_IN_H as guard around header (stephane#765) Thank you @diplfranzhoepfinger * RTU - Check CRC before filtering on slave ID * Minor * Bump version to 3.1.11 * modbus-tcp.c doesn't include config.h, possible workaround - defining HAVE_NETINET_IP_H directly in modbus-tcp.c for Linux builds to force including <netinet/ip.h> which provides IPTOS_LOWDELAY definition --------- Signed-off-by: José Bollo <[email protected]> Signed-off-by: Michael Heimpold <[email protected]> Co-authored-by: Stéphane Raimbault <[email protected]> Co-authored-by: José Bollo <[email protected]> Co-authored-by: Tim Gates <[email protected]> Co-authored-by: Anton Bondarev <[email protected]> Co-authored-by: Richard Ash <[email protected]> Co-authored-by: Stefan Nilsson <[email protected]> Co-authored-by: Marc Haber <[email protected]> Co-authored-by: Michael Heimpold <[email protected]> Co-authored-by: Rick M <[email protected]> Co-authored-by: begasus <[email protected]> Co-authored-by: SZ Lin (林上智) <[email protected]> Co-authored-by: Mochamad Arifin <[email protected]> Co-authored-by: Pascal Bach <[email protected]> Co-authored-by: Heinrich Gsponer <[email protected]> Co-authored-by: along <[email protected]> Co-authored-by: Stéphane Raimbault <[email protected]> Co-authored-by: Mohamed Amine Mzoughi <[email protected]> Co-authored-by: Hans Ulrich Niedermann <[email protected]> Co-authored-by: Jordan Johnson <[email protected]> Co-authored-by: Alexander Polleti <[email protected]> Co-authored-by: David Korczynski <[email protected]> Co-authored-by: 20162026 <[email protected]> Co-authored-by: Yau Yimsing <[email protected]> Co-authored-by: Cedric Boudinet <[email protected]> Co-authored-by: Lauri Nurmi <[email protected]> Co-authored-by: Andreas Nicolai <[email protected]> Co-authored-by: Andreas Nicolai <[email protected]> Co-authored-by: diplfranzhoepfinger <[email protected]>
1 parent 9b7a2f4 commit e285726

File tree

170 files changed

+6071
-4927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+6071
-4927
lines changed

.clabot

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"contributors": [
3+
"0x34d",
4+
"20162026",
5+
"2128506",
6+
"alongl",
7+
"arkapkaj",
8+
"bobbybelieve",
9+
"ccdmuro",
10+
"cedricboudinet",
11+
"DavidKorczynski",
12+
"devotip",
13+
"diplfranzhoepfinger",
14+
"embeddedmz",
15+
"fcntlcc",
16+
"fedepell",
17+
"franzhoepfinger",
18+
"franzhollerer",
19+
"ghorwin",
20+
"jbysewski",
21+
"jcarrano",
22+
"jeroendoggen",
23+
"jetforme",
24+
"jiriki86",
25+
"jordanjohnson56",
26+
"kay30kim",
27+
"kyllingstad",
28+
"mek-x",
29+
"merkag",
30+
"mhei",
31+
"msk-repo-0x4d",
32+
"ndunks",
33+
"peternewman",
34+
"philj56",
35+
"raymondbh",
36+
"ringlej",
37+
"rm5248",
38+
"rongli-eaton",
39+
"sebastianpsm",
40+
"SergeyMy",
41+
"sirsoweird",
42+
"taikiakita",
43+
"vancepym",
44+
"vvck",
45+
"woodsnake"
46+
],
47+
"message": "We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient..."
48+
}

.clang-format

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
BasedOnStyle: LLVM
3+
AlignArrayOfStructures: Left
4+
AlignOperands: true
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveMacros: true
7+
AlignEscapedNewlines: Left
8+
AlignTrailingComments: true
9+
AllowShortBlocksOnASingleLine: false
10+
AllowShortCaseLabelsOnASingleLine: false
11+
AllowShortEnumsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: Never
14+
BreakBeforeBraces: Custom
15+
BraceWrapping:
16+
AfterClass: false
17+
AfterControlStatement: false
18+
AfterEnum: false
19+
AfterFunction: true
20+
AfterNamespace: true
21+
AfterObjCDeclaration: true
22+
AfterStruct: false
23+
AfterUnion: false
24+
AfterExternBlock: false
25+
BeforeCatch: false
26+
BeforeElse: false
27+
IndentBraces: false
28+
SplitEmptyFunction: true
29+
SplitEmptyRecord: true
30+
SplitEmptyNamespace: true
31+
BinPackArguments: false
32+
BinPackParameters: false
33+
ColumnLimit: 90
34+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
35+
IncludeBlocks: Preserve
36+
IndentWidth: 4
37+
ObjCBlockIndentWidth: 4
38+
PointerAlignment: Right
39+
ReferenceAlignment: Right
40+
SpaceAfterCStyleCast: true
41+
SpaceAfterTemplateKeyword: true
42+
SpaceBeforeAssignmentOperators: true
43+
SpaceBeforeCtorInitializerColon: true
44+
SpaceBeforeInheritanceColon: true
45+
SpaceBeforeParens: ControlStatementsExceptForEachMacros
46+
SpaceBeforeRangeBasedForLoopColon: true
47+
SpaceInEmptyParentheses: false
48+
SpacesBeforeTrailingComments: 1
49+
SpacesInAngles: false
50+
SpacesInContainerLiterals: false
51+
SpacesInCStyleCastParentheses: false
52+
SpacesInParentheses: false
53+
SpacesInSquareBrackets: false
54+
SeparateDefinitionBlocks: Always
55+
UseTab: Never
56+
PPIndentWidth: 2

.dir-locals.el

Lines changed: 0 additions & 4 deletions
This file was deleted.

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
# Unix-style newlines with a newline ending every file
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
10+
# Tab indentation (no size specified)
11+
[Makefile]
12+
indent_style = tab

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [stephane]
2+
polar: stephane

.github/workflows/build.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build libmodbus
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: configure
16+
run: ./autogen.sh && ./configure
17+
- name: make
18+
run: make
19+
- name: make distcheck
20+
run: make distcheck

.gitignore

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Temporary files
12
*~
23
*.swp
34
*.o
@@ -7,10 +8,14 @@
78
*.trs
89
.deps
910
.libs
10-
GPATH
11-
GRTAGS
12-
GSYMS
13-
GTAGS
11+
.DS_Store
12+
13+
# Editors
14+
/*.sublime-*
15+
/.vscode
16+
/.venv
17+
18+
# Generated by Autotools
1419
INSTALL
1520
Makefile
1621
Makefile.in
@@ -22,25 +27,25 @@ Makefile.in
2227
/configure.scan
2328
/depcomp
2429
/install-sh
30+
/libmodbus.pc
2531
/libtool
2632
/ltmain.sh
2733
/missing
28-
/libmodbus.pc
2934
/stamp-h1
30-
/*.sublime-*
31-
/.vscode
3235
src/modbus-version.h
3336
src/win32/modbus.dll.manifest
37+
tests/unit-test.h
38+
39+
# mkdocs
40+
/site
41+
42+
# Binary
3443
tests/bandwidth-client
3544
tests/bandwidth-server-many-up
3645
tests/bandwidth-server-one
3746
tests/random-test-client
3847
tests/random-test-server
3948
tests/unit-test-client
40-
tests/unit-test.h
4149
tests/unit-test-server
4250
tests/version
4351
tests/stamp-h2
44-
doc/*.html
45-
doc/*.3
46-
doc/*.7

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
How Do I Submit A Good Bug Report?
2-
----------------------------------
1+
# How Do I Submit A Good Bug Report?
32

43
Please, don't send direct emails to Stéphane Raimbault unless you want
54
commercial support.
65

7-
Take care to read the documentation at http://libmodbus.org/documentation/.
6+
Take care to read the documentation at http://libmodbus.org/.
87

98
- *Be sure it's a bug before creating an issue*, in doubt, post a message on
10-
https://groups.google.com/forum/#!forum/libmodbus or send an email to
11-
9+
<https://groups.google.com/forum/#!forum/libmodbus> or send an email to
10+
1211

13-
- *Use a clear and decriptive title* for the issue to identify
12+
- *Use a clear and descriptive title* for the issue to identify
1413

1514
- *Which version of libmodbus are you using?* you can obtain this information
1615
from your package manager or by running `pkg-config --modversion libmodbus`.
@@ -19,11 +18,11 @@ You can provide the sha1 of the commit if you have fetched the code with `git`.
1918
- *Which operating system are you using?*
2019

2120
- *Describe the exact steps which reproduce the problem* in as many details as
22-
possible. For example, the software/equipement which runs the Modbus server, how
21+
possible. For example, the software/equipment which runs the Modbus server, how
2322
the clients are connected (TCP, RTU, ASCII) and the source code you are using.
2423

2524
- *Enable the debug mode*, libmodbus provides a function to display the content
2625
of the Modbus messages and it's very convenient to analyze issues
27-
(http://libmodbus.org/docs/latest/modbus_set_debug.html).
26+
(http://libmodbus.org/docs/modbus_set_debug/).
2827

2928
Good bug reports provide right and quick fixes!

ISSUE_TEMPLATE.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
Please read the following carefully before submitting this new issue.
22

3-
- Please ensure, that you are really reporting a bug. When in doubt,
4-
post a message on https://groups.google.com/forum/#!forum/libmodbus
5-
or send an email to [email protected]
3+
- Please ensure, that you are really reporting a bug. When in doubt, post a
4+
message on <https://groups.google.com/forum/#!forum/libmodbus> or send an
5+
66

7-
- Please do not open issues to ask questions about using libmodbus.
8-
Use the mailing list for this as there are many more people reading
9-
that list, who could help you.
7+
- Please do not open issues to ask questions about using libmodbus. Use the
8+
mailing list for this as there are many more people reading that list, who
9+
could help you.
1010

11-
- When using libmodbus from a distribution (Debian, Fedora...), please
12-
report the bug first in the bug tracker of the distribution. The
13-
reason for doing so is that the package maintainer should have a chance
14-
to look at the issue first as it might be a packaging error. If/when
15-
the package maintainer comes to the conclusion that is really an upstream
16-
bug, then he/she will usually report it here by himself/herself.
17-
This is because he/she is interested in staying in the notification chain
18-
to decide about a backport as soon as a bugfix is available.
19-
Otherwise you (distribution user) will be asked to do so explicitely.
11+
- When using libmodbus from a distribution (Debian, Fedora...), please report
12+
the bug first in the bug tracker of the distribution. The reason for doing so
13+
is that the package maintainer should have a chance to look at the issue first
14+
as it might be a packaging error. If/when the package maintainer comes to the
15+
conclusion that is really an upstream bug, then he/she will usually report it
16+
here by himself/herself. This is because he/she is interested in staying in
17+
the notification chain to decide about a backport as soon as a bugfix is
18+
available. Otherwise you (distribution user) will be asked to do so
19+
explicitly.
2020

21-
When you get here and you are still convinced that you want report a bug:
21+
When you get here and you are still convinced that you want to report a bug:
2222

23-
- *Use a clear and decriptive title* for the issue to identify
23+
- *Use a clear and descriptive title* for the issue to identify
2424

25-
- *Which version of libmodbus are you using?* you can obtain this information
25+
- *Which version of libmodbus are you using?* you can obtain this information
2626
from your package manager or by running `pkg-config --modversion libmodbus`.
2727
You can provide the sha1 of the commit if you have fetched the code with `git`.
2828

29-
- *Which operating system are you using?*
29+
- *Which operating system are you using?*
3030

31-
- *Describe the exact steps which reproduce the problem* in as many details as
32-
possible. For example, the software/equipement which runs the Modbus server, how
31+
- *Describe the exact steps which reproduce the problem* in as many details as
32+
possible. For example, the software/equipment which runs the Modbus server, how
3333
the clients are connected (TCP, RTU, ASCII) and the source code you are using.
3434

35-
- *Enable the debug mode*, libmodbus provides a function to display the content
35+
- *Enable the debug mode*, libmodbus provides a function to display the content
3636
of the Modbus messages and it's very convenient to analyze issues
37-
(http://libmodbus.org/docs/latest/modbus_set_debug.html).
37+
(<http://libmodbus.org/docs/modbus_set_debug/>).
3838

3939
Good bug reports provide right and quick fixes!
4040

@@ -62,11 +62,11 @@ everything up to and including the following line which starts with ---.
6262

6363
<...>
6464

65-
## Expected behaviour
65+
## Actual behavior if applicable
6666

6767
<...>
6868

69-
## Actual behaviour
69+
## Expected behavior or suggestion
7070

7171
<...>
7272

0 commit comments

Comments
 (0)