Commit Graph
130 Commits
Author SHA1 Message Date
Sang Woo Kim ce775a80cf udpiiu: reject a non-finite or non-positive EPICS_CA_MAX_SEARCH_PERIOD
epicsScanDouble accepts "inf" and "nan", so envGetDoubleConfigParam
returns success for them and the parsed value flows into getMaxPeriod's
only range gate, maxPeriod < maxSearchPeriodLowerLimit. That comparison
is false for both inf and NaN, so a non-finite period reaches
getNTimers(), whose static_cast<unsigned> of 1 + log(maxPeriod/...)/log2
is an undefined float->unsigned conversion: inf aborts the client in
malloc via a garbage nTimers allocation, and NaN drives the search-timer
wheel off a NaN period where every deadline comparison is false.

Gate the parsed value on finite() (from epicsMath.h) and positivity
alongside the parse status, and fall back to the default period. A
non-positive period is not a "low" period to be clamped up to the 60 s
lower limit; it takes the same invalid-input path as inf/NaN.

getMaxPeriod() is getNTimers()'s only caller, so this makes the
conversion finite and positive by construction.
2026-07-21 14:15:43 -05:00
Sang Woo Kim a8180003e9 cac: reject a non-positive or non-finite EPICS_CA_CONN_TMO
A successful parse of EPICS_CA_CONN_TMO stored the value into connTMO
unchecked, so EPICS_CA_CONN_TMO=-5 or =0 left the connection-verify
watchdog deadline permanently in the past. The watchdog then fires
continuously, flooding stderr with "Virtual circuit unresponsive" and
pinning a CPU while updates still arrive. NaN and inf (which
epicsScanDouble also accepts) slip past any ordering comparison: a NaN
period leaves the watchdog deadline arithmetic undefined, and an
infinite period silently disables circuit verification.

Fold the validity check into the existing parse-failure branch, so an
unparsable, non-finite, or non-positive value takes the same path:
warn once and fall back to the 30 s CA_CONN_VERIFY_PERIOD default.
This mirrors the sibling EPICS_CA_MAX_ARRAY_BYTES handling a few lines
below, which already gates a parse failure and an out-of-range value
in one condition, and matches the finite() gate on
EPICS_CA_MAX_SEARCH_PERIOD in udpiiu.cpp.
2026-07-21 14:15:43 -05:00
Michael Davidsaver 7dc46f2168 caget missing NULL check 2026-07-21 07:48:23 -05:00
Érico Nogueira b87b6c91ff Fix UAF in caRepeaterThread
The ca_repeater function has some failure cases which can cause it to
return. In such a situation, a reference to the current thread's
epicsThreadId is kept in the taskwd, causing an eventual use-after-free
when the taskwd tries to determine the task's status.

We fix this problem by removing the thread from the taskwd if
ca_repeater ever returns.
2026-07-06 16:29:52 -07:00
ronaldomercado 2d8a6f91a9 Use consistent language for string termination (#806)
Avoid hyphen, prefer space: "null terminated"
2026-03-18 10:45:25 -05:00
Andrew Johnson e271752158 Added -d option to caRepeater, sets debug level
Added debug messages for client verification.

With -d the repeater shows client events, e.g.

  $ caRepeater -d
  CA Repeater: Attached and initialized
  New client on port 60307
  Verified 1 active clients
  New client on port 52541
  Verified 2 active clients
  Client on port 60307 refused message
  Deleted client on port 60307
  Client on port 52541 refused message
  Deleted client on port 52541
  ^C

Running "caRepeater -dd" also shows beacon forwarding and
individual client verification:

  $ caRepeater -dd
  CA Repeater: Attached and initialized
  New client on port 49968
  Client on port 49968 is alive
  Verified 1 active clients
  Sent to port 49968
  Sent to port 49968
  Sent to port 49968
  New client on port 65377
  Sent to port 49968
  Client on port 49968 is alive
  Client on port 65377 is alive
  Verified 2 active clients
  Sent to port 49968
  Sent to port 65377
  Sent to port 49968
  Sent to port 65377
  Client on port 49968 refused message
  Deleted client on port 49968
  Sent to port 65377
  Sent to port 65377
  Client on port 65377 refused message
  Deleted client on port 65377
  ^C
2026-03-10 12:42:18 -05:00
Andrew Johnson b5df3e002a Various non-functional fixes/changes
Fix EditorConfig failure in modules/libcom/RTEMS/epicsNtp.c
Add dbDefs to Sphinx API index, move devLib to libcom
Rename internal CA enum tag to fix Doxygen complaint
Set Clang's minimum MacOS version for aarch64 CPUs
2026-02-18 11:23:50 -06:00
zimoch db693d4930 enable trim_trailing_whitespace 2026-02-18 10:34:08 -06:00
zimoch cd36c03da4 Enforce consistent space indent style 2026-02-18 10:34:08 -06:00
zimoch 8c9dd71f6e Fix gcc warning 'stringop-truncation' 2026-02-18 10:06:26 -06:00
Michael Davidsaver 71e4635d34 fix testdbCaWaitForEvent()
sync with CA context thread(s) as well as dbCa worker.
2026-01-01 19:07:10 -08:00
zimoch 6d85a36397 remove needless pointer casts 2025-12-17 16:34:58 -08:00
zimoch 90a727c901 Fix spelling errors
Most errors found with:

codespell -L cach,thst,odly,aslo,parm,parms,inpu,ges,prset,pevent,ptd,pring,valu,noo,noe,ned,inout,ro,siz,froms,nd,fo,singl,sart,multy,tthe,allong,ment,inate,nodel,tring,alse,ture,thi,wille,numer

Some more manually found (its -> it's)

c++20: Do not use apostrophe (e.g. can't) in unquoted #error message
2025-12-01 19:00:04 -08:00
bsbevins d763541341 Allow CA clients to determine the server protocol version (#711)
* Allow CA clients to determine the server protocol version

Adds a call to the CA client API that allows a client to determine the server's
protocol minor version number. This is needed to allow the ca-nameserver to
report a server's protocol version correctly to a client.

* ca_host_minor_protocol return for disconnected channels

ca_host_minor_protocol now explicitly returns CA_UKN_MINOR_VERSION for a disconnected channel.
2025-10-08 09:57:30 -05:00
Minijackson 26e9e407f6 docs: add ca_test cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson a0059b6e91 docs: add caEventRate cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson feae322e9a docs: add casw cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson 1b1bb34c83 docs: add catime cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson fe6d946d32 docs: add acctst cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson 004c55503b docs: add caput cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson a9ba1c95b2 docs: add camonitor cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson 72d751f07d docs: add cainfo cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson d279897181 docs: add caget cli reference imported from CAref.html 2025-04-04 08:29:36 -05:00
Minijackson 6fc6304f19 docs(cadef): group CA operations together 2025-04-04 08:27:07 -05:00
Minijackson 0c75f1fe99 import CAref function and return codes reference to doxygen comments
Import all function documentations, return code reference
into the header files, as doc comments,
in the hopes of moving the CAref.html manual to docs.epics-controls.org,
which will be done in a later PR.

Also added doc comments to some other low-hanging fruits,
for example when plain comments where near, or when it was obvious to do so.
2025-04-04 08:27:07 -05:00
zimoch 43e75e3901 decorate functions that do not return 2025-03-05 09:51:57 -06:00
615ba73044 Rules to generate and install Markdown
Markdown can be generated from .pod and .dbd.pod files.
Markdown will be generated and installed by "make inc".

Co-authored-by: Timo Korhonen <timo.korhonen@ess.eu>
Co-authored-by: Andrew Johnson <anj@anl.gov>
2024-10-02 09:16:29 -05:00
Grzegorz Kowalski 5d9ffe15da caget: free PV value after printing 2024-09-04 10:02:49 -05:00
Grzegorz Kowalski 3ac8dcc3de caget: free memory allocated for PV array 2024-09-04 10:02:49 -05:00
Jure Varlec 466a9b565e Change comment style for SPDX tags in C files 2024-09-04 10:02:04 -05:00
Jure Varlec c304b7db53 Add SPDX license tags to templates
Copyright information was gathered using `git log` with per-line history
tracking, which allows following the history of a file through renames.
2024-09-04 10:02:04 -05:00
zimoch 457387ed38 fix warning when dbf_type_to_text is called with an unsigned type argument 2024-08-21 09:35:53 -05:00
Andrew Johnson 785237e41a Remove duplicate link libraries 2024-08-07 09:54:16 -05:00
Michael Davidsaver 87acb98d1e ca: remove hostname length limit when parsing address lists 2023-12-22 10:26:28 -08:00
Andrew Johnson 2e6fd505d2 Use epicsSnprintf() for old MSVC compilers 2023-12-14 11:31:36 -06:00
Andrew Johnson 5ecf7d18a8 Clean up Clang 15 sprintf() warnings in libcom and ca 2023-12-13 13:34:25 -06:00
Michael Davidsaver a352865df9 print ANSI escapes to stderr
unconditionally print ANSI some escapes (to colorize errors)
to the stderr stream.
2023-11-07 15:53:22 -08:00
Ralph Lange d691acc001 ca: init local variable in catime.c
found by static code analysis (cppcheck @ sonarqube)
2023-07-22 08:35:59 -07:00
Doug Murray 1d056c6fe4 Add support for CA tools timeout from environment variable EPICS_CLI_TIMEOUT 2023-07-22 08:24:22 -07:00
zimoch 172597e0e6 avoid accessing dbr_text[type] when type is out of range 2023-03-10 10:56:58 +00:00
Andrew Johnson c068fe3525 capr.pl: Fetch link fields as long strings 2022-12-28 12:43:38 -06:00
Torsten Bögershausen a8e8d22c31 iocinf.cpp: Hostnames may be longer than 32 bytes
Found here at ESS:

(all in one line)
EPICS_CA_ADDR_LIST=averylonghostname.mylabnetwork.technicalnetwork.example.com
EPICS_CA_AUTO_ADDR_LIST=NO
caget somePVnam

leads to something like this:
CA.Client.Exception...............................................
    Warning: "Empty PV search address list"
    Source File: ../udpiiu.cpp line 403
    Current Time: Thu Jun 09 2022 10:10:47.804161447

Problem desription:
addAddrToChannelAccessAddressList() will collect what ever we specify in
EPICS_CA_ADDR_LIST for channel access.
That function will add IP-addresses to the search list.
hostnames are possible, but are ignored if longer than 32 bytes,
because buf is too short.

If a hostname can be resolved into an IP, that is fine,
if not that is "fine as well" (better say: silently ignored):
If, and only if, EPICS_CA_AUTO_ADDR_LIST=NO is given then the one
and only too long hostname will be ignored and lead to an
"Empty PV search address list".

If EPICS_CA_AUTO_ADDR_LIST=YES (or nothing) is specified, the search list
is not empty, and EPICS will search all broadcast addresses.
This will eventually lead into a timout.

Solution:
Increase the buf size in addAddrToChannelAccessAddressList() from 32 to 256

The maximum length for a hostname is 255:
https://www.ietf.org/rfc/rfc1034.txt

If we add one byte for the string terminating '\0', we need 256 bytes.

And yes, this patch neglets the fact that a user can specify HOSTNAME:PORT,
which may need another 6 bytes. To put it the other way around:
In this case the hostname length is limited to 250 bytes,
which is still long enough in practice.
2022-09-02 18:28:34 -07:00
Andrew Johnson b88b35d117 Enhancements to the capr.pl script 2022-08-16 11:58:35 -05:00
Andrew Johnson d82ab819ef Cap5 support for zero-length long strings 2022-07-13 13:24:54 -05:00
Andrew Johnson 571165df26 Stop Clang-12 warnings from Perl XS code 2022-07-04 15:55:18 -05:00
Minijackson a722bb9289 treewide: add usage help to various iocsh functions 2022-06-20 08:09:42 -07:00
Andrew Johnson e329fa3296 CA Client: Protect against epicsTime::strftime() throwing
libCa shouldn't cause an application to abort with an uncaught
exception on a machine that has timezone problems just because
we can't convert the current time into a string.
2022-04-24 12:50:40 -05:00
Andrew Johnson 6d3821adb8 Soft-links to capr.pl and makeBaseApp.pl scripts now work
The other Perl scripts that use FindBin for their lib path could
have the same changes applied, but these two scripts are the ones
normally run by hand so might get soft-linked by an installer.
Without this change these scripts don't actually work if run from
a soft-link instead of directly.
2022-04-18 20:46:48 -05:00
Michael Davidsaver b0e2e8426f Quiet warning 2022-04-16 13:23:58 -07:00
Andrew Johnson 7cb80d5a17 Merge Dirk's fix_epicsInt8 branch into 7.0 2022-01-24 13:32:16 -06:00