Skip to content

Commit

Permalink
Fix print_supported_protocols and print_supported_protocols_usage
Browse files Browse the repository at this point in the history
These were broken in 7cb8996, when the
empty sentinel value at the end of the array was removed, without changing
the way these functions iterate over that array.

For some reason, this continues to work on Linux (probably due to `calloc`
allocating more zeroed bytes than we request, in
`openconnect_get_supported_protocols`), but is causing the expected SIGSEGV on
Solaris:
https://lists.infradead.org/pipermail/openconnect-devel/2020-April/005640.html

Fix:

- Modify `print_supported_protocols` and `print_supported_protocols_usage` to
  rely on the length returned by `openconnect_get_supported_protocols`.
- Restore the sentinel value at the end of the array returned by
  `openconnect_get_supported_protocols`, to preserve ABI compatibility for
  other users who may depend on this sentinel.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
  • Loading branch information
dlenski committed Apr 20, 2020
1 parent 52bf0e9 commit ca8ec5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion library.c
Expand Up @@ -195,7 +195,13 @@ int openconnect_get_supported_protocols(struct oc_vpn_proto **protos)
struct oc_vpn_proto *pr;
int i;

*protos = pr = calloc(NR_PROTOS, sizeof(*pr));
/* The original version of this function included an all-zero
* sentinel value at the end of the array, so we must continue
* to do so for ABI compatibility even though it's
* functionally redundant as a marker of the array's length,
* along with the explicit length in the return value.
*/
*protos = pr = calloc(NR_PROTOS + 1, sizeof(*pr));
if (!pr)
return -ENOMEM;

Expand Down
12 changes: 8 additions & 4 deletions main.c
Expand Up @@ -659,10 +659,12 @@ static void print_supported_protocols(void)
{
const char *comma = ", ", *sep = comma + 1;
struct oc_vpn_proto *protos, *p;
int n;

if (openconnect_get_supported_protocols(&protos)>=0) {
n = openconnect_get_supported_protocols(&protos);
if (n>=0) {
printf(_("Supported protocols:"));
for (p=protos; p->name; p++) {
for (p=protos; n; p++, n--) {
printf("%s%s%s", sep, p->name, p==protos ? _(" (default)") : "");
sep = comma;
}
Expand All @@ -674,10 +676,12 @@ static void print_supported_protocols(void)
static void print_supported_protocols_usage(void)
{
struct oc_vpn_proto *protos, *p;
int n;

if (openconnect_get_supported_protocols(&protos)>=0) {
n = openconnect_get_supported_protocols(&protos);
if (n>=0) {
printf("\n%s:\n", _("Set VPN protocol"));
for (p=protos; p->name; p++)
for (p=protos; n; p++, n--)
printf(" --protocol=%-16s %s%s\n",
p->name, p->description, p==protos ? _(" (default)") : "");
openconnect_free_supported_protocols(protos);
Expand Down

0 comments on commit ca8ec5e

Please sign in to comment.