From c5740c0dd0d2d53e49a2f99f9bd0d96da168b392 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 8 Oct 2014 14:18:08 -0500 Subject: [PATCH 1/7] Add relPaths.sh target to convertRelease.pl This is a /bin/sh syntax version of the dllPath.bat file, needed to run IOCs under Cygwin when SHARED_LIBRARIES=YES. --- configure/RULES.ioc | 7 ++++--- documentation/RELEASE_NOTES.html | 14 ++++++++++++++ src/makeBaseApp/Makefile | 4 ++++ .../top/exampleBoot/ioc/Makefile@cygwin | 5 +++++ .../top/exampleBoot/ioc/Makefile@windows | 5 +++++ src/makeBaseApp/top/iocBoot/ioc/Makefile@cygwin | 5 +++++ src/makeBaseApp/top/iocBoot/ioc/Makefile@windows | 5 +++++ src/tools/convertRelease.pl | 16 +++++++++++++--- 8 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/makeBaseApp/top/exampleBoot/ioc/Makefile@cygwin create mode 100644 src/makeBaseApp/top/exampleBoot/ioc/Makefile@windows create mode 100644 src/makeBaseApp/top/iocBoot/ioc/Makefile@cygwin create mode 100644 src/makeBaseApp/top/iocBoot/ioc/Makefile@windows diff --git a/configure/RULES.ioc b/configure/RULES.ioc index 6b2150fcb..1024fcb22 100644 --- a/configure/RULES.ioc +++ b/configure/RULES.ioc @@ -18,16 +18,17 @@ ifeq ($(filter $(ARCH),$(BUILD_ARCHS)),$(ARCH)) buildInstall$(DIVIDER)$(ARCH) buildInstall: $(TARGETS) clean$(DIVIDER)$(ARCH) clean: - $(RM) cdCommands envPaths dllPath.bat + $(RM) cdCommands envPaths dllPath.bat relPaths.sh else buildInstall$(DIVIDER)$(ARCH) buildInstall: clean$(DIVIDER)$(ARCH) clean: endif -cdCommands envPaths dllPath.bat: $(wildcard $(TOP)/configure/RELEASE*) \ +cdCommands envPaths dllPath.bat relPaths.sh: \ + $(wildcard $(TOP)/configure/RELEASE*) \ $(wildcard $(TOP)/configure/CONFIG_SITE*) $(INSTALL_BIN) $(CONVERTRELEASE) -a $(ARCH) -t $(IOCS_APPL_TOP) $@ realclean: - $(RM) cdCommands envPaths dllPath.bat + $(RM) cdCommands envPaths dllPath.bat relPaths.sh diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index 3d8747947..d906ec904 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -13,6 +13,20 @@ +

Better Cygwin IOC Application Support

+ +

IOC applications built for Cygwin with shared libraries need to have PATH +configured to include all of the bin directories for support modules listed in +the RELEASE file. For applications run from the Windows cmd.exe shell the +Makefile in the application's iocBoot/ioc directory can be set to build a file +dllPath.bat which performs the appropriate changes to PATH, but this file uses +syntax which is unique to the cmd.exe shell. Cygwin applications can now add a +target relPaths.sh to this Makefile, which will generate a file appropriate for +sourcing in the Bash shell instead.

+ +

The makeBaseApp.pl templates now include this file in the list of targets to +be built in the iocBoot/ioc/Makefile for Cygwin architectures.

+

Reject NULL callback functions in ca_array_*_callback

The two CA routines ca_array_get_callback() and ca_array_put_callback() were diff --git a/src/makeBaseApp/Makefile b/src/makeBaseApp/Makefile index c7f89f8e1..7b728394d 100644 --- a/src/makeBaseApp/Makefile +++ b/src/makeBaseApp/Makefile @@ -53,6 +53,8 @@ TEMPLATES += top/exampleBoot/nfsCommands@RTEMS TEMPLATES += top/exampleBoot/ioc/Makefile@Common TEMPLATES += top/exampleBoot/ioc/Makefile@vxWorks TEMPLATES += top/exampleBoot/ioc/Makefile@win32 +TEMPLATES += top/exampleBoot/ioc/Makefile@windows +TEMPLATES += top/exampleBoot/ioc/Makefile@cygwin TEMPLATES += top/exampleBoot/ioc/st.cmd@Common TEMPLATES += top/exampleBoot/ioc/st.cmd@vxWorks TEMPLATES += top/exampleBoot/ioc/st.cmd@RTEMS @@ -82,6 +84,8 @@ TEMPLATES += top/iocBoot/nfsCommands@RTEMS TEMPLATES += top/iocBoot/ioc/Makefile@Common TEMPLATES += top/iocBoot/ioc/Makefile@vxWorks TEMPLATES += top/iocBoot/ioc/Makefile@win32 +TEMPLATES += top/iocBoot/ioc/Makefile@windows +TEMPLATES += top/iocBoot/ioc/Makefile@cygwin TEMPLATES += top/iocBoot/ioc/st.cmd@Common TEMPLATES += top/iocBoot/ioc/st.cmd@Cross TEMPLATES += top/iocBoot/ioc/st.cmd@vxWorks diff --git a/src/makeBaseApp/top/exampleBoot/ioc/Makefile@cygwin b/src/makeBaseApp/top/exampleBoot/ioc/Makefile@cygwin new file mode 100644 index 000000000..77c3215d7 --- /dev/null +++ b/src/makeBaseApp/top/exampleBoot/ioc/Makefile@cygwin @@ -0,0 +1,5 @@ +TOP = ../.. +include $(TOP)/configure/CONFIG +ARCH = _ARCH_ +TARGETS = envPaths relPaths.sh +include $(TOP)/configure/RULES.ioc diff --git a/src/makeBaseApp/top/exampleBoot/ioc/Makefile@windows b/src/makeBaseApp/top/exampleBoot/ioc/Makefile@windows new file mode 100644 index 000000000..59b32d734 --- /dev/null +++ b/src/makeBaseApp/top/exampleBoot/ioc/Makefile@windows @@ -0,0 +1,5 @@ +TOP = ../.. +include $(TOP)/configure/CONFIG +ARCH = _ARCH_ +TARGETS = envPaths dllPath.bat +include $(TOP)/configure/RULES.ioc diff --git a/src/makeBaseApp/top/iocBoot/ioc/Makefile@cygwin b/src/makeBaseApp/top/iocBoot/ioc/Makefile@cygwin new file mode 100644 index 000000000..77c3215d7 --- /dev/null +++ b/src/makeBaseApp/top/iocBoot/ioc/Makefile@cygwin @@ -0,0 +1,5 @@ +TOP = ../.. +include $(TOP)/configure/CONFIG +ARCH = _ARCH_ +TARGETS = envPaths relPaths.sh +include $(TOP)/configure/RULES.ioc diff --git a/src/makeBaseApp/top/iocBoot/ioc/Makefile@windows b/src/makeBaseApp/top/iocBoot/ioc/Makefile@windows new file mode 100644 index 000000000..59b32d734 --- /dev/null +++ b/src/makeBaseApp/top/iocBoot/ioc/Makefile@windows @@ -0,0 +1,5 @@ +TOP = ../.. +include $(TOP)/configure/CONFIG +ARCH = _ARCH_ +TARGETS = envPaths dllPath.bat +include $(TOP)/configure/RULES.ioc diff --git a/src/tools/convertRelease.pl b/src/tools/convertRelease.pl index 5b0890425..abf63c3ec 100644 --- a/src/tools/convertRelease.pl +++ b/src/tools/convertRelease.pl @@ -82,6 +82,7 @@ expandRelease(\%macros, \@apps); for ($outfile) { m/releaseTops/ and do { &releaseTops; last; }; m/dllPath\.bat/ and do { &dllPath; last; }; + m/relPaths\.sh/ and do { &relPaths; last; }; m/cdCommands/ and do { &cdCommands; last; }; m/envPaths/ and do { &envPaths; last; }; m/checkRelease/ and do { &checkRelease; last; }; @@ -96,7 +97,8 @@ sub HELP_MESSAGE { Usage: convertRelease.pl [-a arch] [-T top] [-t ioctop] outfile where outfile is one of: releaseTops - lists the module names defined in RELEASE*s - dllPath.bat - path changes for cmd.exe to find WIN32 DLLs + dllPath.bat - path changes for cmd.exe to find Windows DLLs + relPaths.sh - path changes for bash to add RELEASE bin dir's cdCommands - generate cd path strings for vxWorks IOCs envPaths - generate epicsEnvSet commands for other IOCs checkRelease - checks consistency with support modules @@ -113,13 +115,21 @@ sub releaseTops { } # -# Generate Path files so Windows can find our DLLs +# Generate Path files so Windows/Cygwin can find our DLLs # sub dllPath { unlink $outfile; open(OUT, ">$outfile") or die "$! creating $outfile"; print OUT "\@ECHO OFF\n"; - print OUT "PATH %PATH%;", join(';', binDirs()), "\n"; + print OUT "PATH \%PATH\%;", join(';', binDirs()), "\n"; + close OUT; +} + +sub relPaths { + unlink $outfile; + open(OUT, ">$outfile") or die "$! creating $outfile"; + print OUT "export PATH=\$PATH:", + join(':', map {m/\s/ ? "\"$_\"" : $_ } binDirs()), "\n"; close OUT; } From 49a9d649460c8f6ebdbf319ff9adfab260713550 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Thu, 9 Oct 2014 14:12:39 +0200 Subject: [PATCH 2/7] catools: better out-of-bounds handling when printing enums as DBR_GR/DBR_CTRL --- src/catools/tool_lib.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/catools/tool_lib.c b/src/catools/tool_lib.c index ddead1115..71b444ccb 100644 --- a/src/catools/tool_lib.c +++ b/src/catools/tool_lib.c @@ -162,11 +162,21 @@ char *val2str (const void *v, unsigned type, int index) case DBR_ENUM: { dbr_enum_t *val = (dbr_enum_t *)val_ptr; - if (dbr_type_is_GR(type) && !enumAsNr) - sprintf(str, "%s", ((struct dbr_gr_enum *)v)->strs[val[index]]); - else if (dbr_type_is_CTRL(type) && !enumAsNr) - sprintf(str, "%s", ((struct dbr_ctrl_enum *)v)->strs[val[index]]); - else + if (dbr_type_is_GR(type) && !enumAsNr) { + if (val[index] >= MAX_ENUM_STATES) + sprintf(str, "Illegal Value (%d)", val[index]); + else if (val[index] >= ((struct dbr_gr_enum *)v)->no_str) + sprintf(str, "Enum Index Overflow (%d)", val[index]); + else + sprintf(str, "%s", ((struct dbr_gr_enum *)v)->strs[val[index]]); + } else if (dbr_type_is_CTRL(type) && !enumAsNr) { + if (val[index] >= MAX_ENUM_STATES) + sprintf(str, "Illegal Value (%d)", val[index]); + else if (val[index] >= ((struct dbr_ctrl_enum *)v)->no_str) + sprintf(str, "Enum Index Overflow (%d)", val[index]); + else + sprintf(str, "%s", ((struct dbr_ctrl_enum *)v)->strs[val[index]]); + } else sprintf(str, "%d", val[index]); } } From f59123bd3c825278c4918d59c8b8d5e7ec007009 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 17 Oct 2014 11:48:18 -0500 Subject: [PATCH 3/7] Added Windows-x64-debug cross-build config file --- configure/os/CONFIG.windows-x64.windows-x64-debug | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 configure/os/CONFIG.windows-x64.windows-x64-debug diff --git a/configure/os/CONFIG.windows-x64.windows-x64-debug b/configure/os/CONFIG.windows-x64.windows-x64-debug new file mode 100644 index 000000000..d9f675aac --- /dev/null +++ b/configure/os/CONFIG.windows-x64.windows-x64-debug @@ -0,0 +1,12 @@ +# CONFIG.windows-x64.windows-x64-debug +# +# $Revision-Id$ +# This file is maintained by the build community. +# +# Definitions for windows-x64 compiler host - windows-x64 debug compiler target builds +# Sites may override these definitions in CONFIG_SITE.windows-x64.windows-x64-debug +#------------------------------------------------------- + +include $(CONFIG)/os/CONFIG.windows-x64.windows-x64 + +HOST_OPT=NO From f808e4309dd432e7b578fe0abe8626002f82ce77 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 17 Oct 2014 15:19:00 -0500 Subject: [PATCH 4/7] cap5 Fixes 1. Support subscribing for DBR_GR_ENUM or DBR_CTRL_ENUM 2. Fix doc example on how to combine timestamp parts --- src/cap5/CA.pm | 4 ++-- src/cap5/Cap5.xs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cap5/CA.pm b/src/cap5/CA.pm index 48297162c..a6bd1ed23 100644 --- a/src/cap5/CA.pm +++ b/src/cap5/CA.pm @@ -95,8 +95,8 @@ CA - Perl 5 interface to EPICS Channel Access } else { printf " Value: %g\n", $data->{value}; printf " Severity: %s\n", $data->{severity}; - printf " Timestamp: %d.%09d\n", - $data->{stamp}, $data->{stamp_fraction}; + printf " Timestamp: %.6f\n", + $data->{stamp} + $data->{stamp_fraction}; } } diff --git a/src/cap5/Cap5.xs b/src/cap5/Cap5.xs index 785041229..6a2b3a984 100644 --- a/src/cap5/Cap5.xs +++ b/src/cap5/Cap5.xs @@ -915,16 +915,18 @@ SV * CA_create_subscription(SV *ca_ref, const char *mask_str, SV *sub, ...) { dbr_text_to_type(treq, type); if (type < 0) { - croak_msg = "Unknown data type"; + croak_msg = "Unknown CA data type"; goto exit_croak; } if (type == DBR_PUT_ACKT || type == DBR_PUT_ACKS) { croak_msg = "DBR_PUT_ACK types are write-only"; goto exit_croak; - } else if (type == DBR_CLASS_NAME || + } else if (type == DBR_GR_ENUM || + type == DBR_CTRL_ENUM || + type == DBR_CLASS_NAME || type == DBR_STSACK_STRING) - /* These break the dbr_type_is macros */ ; + /* These above types are supported */ ; else if (dbr_type_is_SHORT(type)) type += (DBR_LONG - DBR_SHORT); else if (dbr_type_is_FLOAT(type)) From f0156119be5130317ff5b7681949a5b717a99fbb Mon Sep 17 00:00:00 2001 From: "J. Lewis Muir" Date: Wed, 22 Oct 2014 11:03:40 -0500 Subject: [PATCH 5/7] cap5: Fix doc typos --- src/cap5/CA.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cap5/CA.pm b/src/cap5/CA.pm index a6bd1ed23..ce9e992da 100644 --- a/src/cap5/CA.pm +++ b/src/cap5/CA.pm @@ -235,7 +235,7 @@ C with an exception object in the callback and catch that using C in the main thread are not likely to succeed and will probably result in a crash. Callbacks should not perform any operations that would block for more than a fraction of a second as this will hold up network communications with the -relevent server and could cause the Perl program and/or the Channel Access +relevant server and could cause the Perl program and/or the Channel Access server to crash. Calling C<< CA->pend_event >> from within a callback is not permitted by the underlying Channel Access library. @@ -291,7 +291,7 @@ apply to the callback subroutine as described in C above. =item put_acks( I, I ) -Applications that need to ackowledge alarms by doing a C with type +Applications that need to acknowledge alarms by doing a C with type C can do so using the C method. The severity argument may be provided as an integer from zero through three or as a string containing one of the corresponding EPICS severity names C, C, C or @@ -325,11 +325,12 @@ The data provided to a callback function registered with either C or C can be a scalar value or a reference to an array or a hash, depending on the data type that was used for the data transfer. If the request was for a single item of one of the basic data types, the data argument -will be a perl scalar that holds the value directly. If the request was for +will be a Perl scalar that holds the value directly. If the request was for multiple items of one of the basic types, the data argument will be a reference to an array holding the data. There is one exception though; if the data type requested was for an array of C values that array will be represented -as a single Perl string contining all the characters before the first zero byte. +as a single Perl string containing all the characters before the first zero +byte. If the request was for one of the compound data types, the data argument will be a reference to a hash with keys as described below. Keys that are not classed @@ -355,7 +356,7 @@ widened from the original type used to request or subscribe for the data. The number of elements in the data returned by the server. If the data type is C the value given for C is the number of bytes (including any trailing zeros) returned by the server, although the value field is given as a -Perl string contining all the characters before the first zero byte. +Perl string containing all the characters before the first zero byte. =back @@ -417,7 +418,7 @@ Present only when I is C or C. =item stamp The process variable timestamp, converted to a local C. This value is -suitable for passing to the perl C or C functions. +suitable for passing to the Perl C or C functions. Present only when I is C. @@ -620,15 +621,15 @@ passing C as the subroutine reference. Errors in using the library will be indicated by the module throwing an exception, i.e. calling C with an appropriate error message. These -exceptions can be caught using the standard Parl C statement and +exceptions can be caught using the standard Perl C statement and testing the C<$@> variable afterwards; if not caught, they will cause the running program to C with an appropriate error message pointing to the program line that called the C library. -Errors messages reported by the underlying CA client library all start with the +Error messages reported by the underlying CA client library all start with the string C and the remainder of the symbol for the associated CA error number, and are followed after a space-hyphen-space by a human-readable message -describing the error. Errors that are detected by the perl interface layer do +describing the error. Errors that are detected by the Perl interface layer do not follow this pattern, but are still printable strings. From 53d9a07f644420bdfb8a901f9dc632fb5dbe80fe Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 5 Nov 2014 10:06:02 -0600 Subject: [PATCH 6/7] Fix buffer overflow in epicsStrnRawFromEscaped lp:1388313 --- documentation/RELEASE_NOTES.html | 5 ++++ src/libCom/misc/epicsString.c | 7 +++++- src/libCom/test/epicsStringTest.c | 40 ++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index d906ec904..bd0a375ad 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -13,6 +13,11 @@ +

Fix buffer overflow in epicsStrnRawFromEscaped()

+ +

Launchpad bug +1388313 reported by Bruce Hill and Chris Ford.

+

Better Cygwin IOC Application Support

IOC applications built for Cygwin with shared libraries need to have PATH diff --git a/src/libCom/misc/epicsString.c b/src/libCom/misc/epicsString.c index f5c61944d..4ee9fed35 100644 --- a/src/libCom/misc/epicsString.c +++ b/src/libCom/misc/epicsString.c @@ -43,6 +43,9 @@ int epicsStrnRawFromEscaped(char *to, size_t outsize, const char *from, char c; int nto = 0, nfrom = 0; + if (outsize == 0) + return 0; + while ((c = *pfrom++) && nto < outsize && nfrom < inlen) { nfrom++; if (c == '\\') { @@ -100,7 +103,9 @@ int epicsStrnRawFromEscaped(char *to, size_t outsize, const char *from, *pto++ = c; nto++; } } - *pto = '\0'; /* NOTE that nto does not have to be incremented */ + if (nto == outsize) + pto--; + *pto = '\0'; return nto; } diff --git a/src/libCom/test/epicsStringTest.c b/src/libCom/test/epicsStringTest.c index 72944f7c6..27ac53678 100644 --- a/src/libCom/test/epicsStringTest.c +++ b/src/libCom/test/epicsStringTest.c @@ -48,9 +48,11 @@ MAIN(epicsStringTest) const char * const a = "a"; const char * const abcd = "abcd"; const char * const abcde = "abcde"; + char result[8]; char *s; + int status; - testPlan(281); + testPlan(299); testChars(); @@ -85,5 +87,41 @@ MAIN(epicsStringTest) testOk1(epicsStrHash(abcd, 0) == epicsMemHash(abcde, 4, 0)); testOk1(epicsStrHash(abcd, 0) != epicsMemHash("abcd\0", 5, 0)); + memset(result, 'x', sizeof(result)); + status = epicsStrnEscapedFromRaw(result, 4, ABCD, 3); + testOk(status == 3, "epicsStrnEscapedFromRaw returned %d (exp. 3)", status); + testOk(result[4] == 'x', "epicsStrnEscapedFromRaw no buffer overrun"); + testOk(result[3] == 0, "epicsStrnEscapedFromRaw 0-terminated"); + + memset(result, 'x', sizeof(result)); + status = epicsStrnEscapedFromRaw(result, 4, ABCD, 4); + testOk(status == 4, "epicsStrnEscapedFromRaw returned %d (exp. 4)", status); + testOk(result[4] == 'x', "epicsStrnEscapedFromRaw no buffer overrun"); + testOk(result[3] == 0, "epicsStrnEscapedFromRaw 0-terminated"); + + memset(result, 'x', sizeof(result)); + status = epicsStrnEscapedFromRaw(result, 4, ABCDE, 5); + testOk(status == 5, "epicsStrnEscapedFromRaw returned %d (exp. 5)", status); + testOk(result[4] == 'x', "epicsStrnEscapedFromRaw no buffer overrun"); + testOk(result[3] == 0, "epicsStrnEscapedFromRaw 0-terminated"); + + memset(result, 'x', sizeof(result)); + status = epicsStrnRawFromEscaped(result, 4, ABCD, 3); + testOk(status == 3, "epicsStrnRawFromEscaped returned %d (exp. 3)", status); + testOk(result[4] == 'x', "epicsStrnRawFromEscaped no buffer overrun"); + testOk(result[3] == 0, "epicsStrnRawFromEscaped 0-terminated"); + + memset(result, 'x', sizeof(result)); + status = epicsStrnRawFromEscaped(result, 4, ABCD, 4); + testOk(status == 4, "epicsStrnRawFromEscaped returned %d (exp. 4)", status); + testOk(result[4] == 'x', "epicsStrnRawFromEscaped no buffer overrun"); + testOk(result[3] == 0, "epicsStrnRawFromEscaped 0-terminated"); + + memset(result, 'x', sizeof(result)); + status = epicsStrnRawFromEscaped(result, 4, ABCDE, 5); + testOk(status == 4, "epicsStrnRawFromEscaped returned %d (exp. 4)", status); + testOk(result[4] == 'x', "epicsStrnRawFromEscaped no buffer overrun"); + testOk(result[3] == 0, "epicsStrnRawFromEscaped 0-terminated"); + return testDone(); } From 0d0ac88242ecf1c7fca182acb8c1b6b66aa6b6d2 Mon Sep 17 00:00:00 2001 From: "J. Lewis Muir" Date: Fri, 7 Nov 2014 14:56:41 -0600 Subject: [PATCH 7/7] doc: Fix typos in CA reference manual --- src/ca/CAref.html | 111 +++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/src/ca/CAref.html b/src/ca/CAref.html index 4efe23d70..ced420085 100644 --- a/src/ca/CAref.html +++ b/src/ca/CAref.html @@ -109,7 +109,7 @@ $Date$