Commit Graph

1371 Commits

Author SHA1 Message Date
Michael Tokarev
c80c04b235 spelling fixes (underun prefered relase encyption confunder)
[abartlet@samba.org: From Samba debian package at
 https://salsa.debian.org/samba-team/samba/-/blob/master/debian/patches/heimdal-spelling.patch?ref_type=heads]

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2024-06-16 23:28:43 -04:00
Nicolas Williams
c922303dd0 asn1: Do not emit the same ASN.1 C comments repeatedly 2023-09-21 23:08:34 -04:00
Nicolas Williams
cfd2ccb546 asn1: Do not emit extra typedefs that cause warnings 2023-09-21 23:08:34 -04:00
Taylor R Campbell
8ac4266021 Makefile.am: Set AM_YFLAGS and AM_LFLAGS, not YFLAGS or LFLAGS.
YFLAGS and LFLAGS are reserved for the user to set, not for makefiles
to set:
https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html

fix https://github.com/heimdal/heimdal/issues/1171
2023-06-21 20:06:58 -05:00
Taylor R Campbell
ca0e53b64f Pass -d to yacc(1) so it generates the header file.
Bison must generate this unsolicited, but BSD yacc does not.

The makefiles for lib/com_err and lib/sl already did this; this
change just adds it to lib/asn1 and lib/hx509 too.

fix https://github.com/heimdal/heimdal/issues/1100
2023-06-21 16:07:16 -05:00
Robert Manner
37cd2c16b8 asn1/check-gen.c: disable some non working bignum tests on 32 bit systems 2023-06-20 12:57:28 -05:00
Robert Manner
65e5b0ab79 roken/parse_bytes: fix test for >= terabyte units on 32 bit systems
On 32 bit systems, sizeof(ssize_t) and sizeof(unsigned long aka UL) is
32 bits which is not able to hold the value of a terabyte.
2023-06-20 12:57:28 -05:00
Taylor R Campbell
a142767598 Fix ctype.h misuse.
Excluded: libtomath and libedit files, most of which appear to be
testing or example code not involved in production, and which are
derived from an upstream that should perhaps have patches submitted
upstream instead.

fix https://github.com/heimdal/heimdal/issues/1111
2023-05-26 14:10:11 -05:00
Norbert Bokor
14aca7a831 heimdal/asn1: do not throw error when trying to allocate 0 bytes of memory 2023-02-06 18:17:48 -06:00
Nicolas Williams
ae4ccb87da asn1: Don't check for NULL when it's not (template_members()) 2023-01-04 16:07:13 -06:00
Nicolas Williams
20c4c0dea9 asn1: Fix ENOMEM leak in der_print_bit_string() 2023-01-04 00:43:35 -06:00
Nicolas Williams
26b1acf3b8 asn1: Remove unused variable assignment in main.c 2023-01-04 00:43:35 -06:00
Nicolas Williams
f0feaab938 asn1: Template CHOICE element 0 bug
While we no longer have a decoder CHOICE element 0 bug, we did still
have one encode and copy and free that was leading to a memory leak (and
_save trashing) prior to the fix for

    asn1: Fix 1-byte leaks in der_copy_octet_string()

This commit fixes that.
2022-11-30 11:59:45 -06:00
Nicolas Williams
50eb3bc245 asn1: Fix 1-byte leaks in der_copy_octet_string()
We sometimes do things like `memset(&cert, 0, sizeof(cert))` then
`copy_Certificate(&cert, &cert_copy)`, and then we end up leaking a
byte in `der_copy_octet_string()` due to it having this code:

```C
der_copy_octet_string (const heim_octet_string *from, heim_octet_string *to)
{
    assert(from->length == 0 || (from->length > 0 && from->data != NULL));
    if (from->length == 0)
	to->data = calloc(1, 1);
    else
	to->data = malloc(from->length);
    ...
}
```

The traces where this happens always involve the `_save` field of
`Name` or `TBSCertificate`.

This code was assuming that length 0 octet strings are expected to have
a non-NULL `data`, probably in case the C library's allocator returns
non-NULL pointers for `malloc(0)`, but then, why not just call
`malloc(0)`?  But calling `malloc(0)` would then still lead to this leak
in on such systems.

Now, `der_free_octet_string()` does unconditionally `free()` the
string's `data`, so the leak really is not there but elsewhere, probably
in `lib/asn1/template.c:_asn1_free()`, but it clearly does
`der_free_octet_string()` the `_save` field of types that have it.
2022-11-30 11:59:45 -06:00
Luke Howard
b4c0ef9970 asn1: ensure quoting of default string values
5398425c introduced support for propagating ASN.1 default values to the emitted
JSON, but it neglected to quote string values, which caused ASN.1 parsing
errors. Correct this.
2022-11-26 22:39:37 +11:00
Luke Howard
16179383fb asn1: note IMPLICIT CHOICE promoted to EXPLICIT
Record when a CHOICE field is promoted from IMPLICIT to EXPLICIT and convey
this in the ASN.1 compiler's JSON output, so that other tools (e.g. which have
a representation isomorphic to the original ASN.1) may use it.
2022-11-17 17:03:19 -06:00
Luke Howard
5398425cd2 asn1: propagate default values to JSON
Propagate ASN.1 DEFAULT values to ASN.1 compiler JSON output, with the defval
key.
2022-11-17 17:03:19 -06:00
Luke Howard
bc3d9c0115 asn1: JSON output open type IDs
Include open type IDs in JSON output of ASN.1 compiler.
2022-11-17 17:03:19 -06:00
Luke Howard
6a3604caf1 asn1: fix incorrect tag value for UT_UniversalString 2022-11-17 17:03:19 -06:00
Volker Lendecke
f4faaeaba3 heimdal: Fix the 32-bit build on FreeBSD
Format string fixes that fail in the Samba build on a 32-bit machine

Signed-off-by: Volker Lendecke <vl@samba.org>
2022-11-16 23:46:46 -05:00
Jeffrey Altman
a9fca332da lib/asn1: free_type fix HEIM_FALLTHROUGH usage
To function HEIM_FALLTHROUGH should not be embedded in a comment.
2022-11-16 12:23:40 -05:00
Nicolas Williams
9c9dac2b16 asn1: CVE-2022-44640 invalid free in ASN.1 codec
Heimdal's ASN.1 compiler generates code that allows specially
crafted DER encodings of CHOICEs to invoke the wrong free function
on the decoded structure upon decode error.  This is known to impact
the Heimdal KDC, leading to an invalid free() of an address partly
or wholly under the control of the attacker, in turn leading to a
potential remote code execution (RCE) vulnerability.

This error affects the DER codec for all CHOICE types used in
Heimdal, though not all cases will be exploitable.  We have not
completed a thorough analysis of all the Heimdal components
affected, thus the Kerberos client, the X.509 library, and other
parts, may be affected as well.

This bug has been in Heimdal since 2005.  It was first reported by
Douglas Bagnall, though it had been found independently by the
Heimdal maintainers via fuzzing a few weeks earlier.
2022-11-15 17:51:45 -06:00
Nicolas Williams
e4311f3a82 asn1: Fix UB and incorrect codec for unconstrained INTEGER values of -1 2022-11-01 16:10:57 -05:00
Daria Phoebe Brashear
133f517482 rewrite fallthrough to HEIM_FALLTHROUGH to deal with new Apple SDKs
Apple clang version 14.0.0 (clang-1400.0.17.3.1) fails the build
because stds.h defines `fallthrough` as a macro which is then
expanded when base.h evaluates

  # if __has_attribute(fallthrough) && __clang_major__ >= 5

The macOS SDK defines `DISPATCH_FALLTHROUGH` as the macro instead
of `fallthrough`.

This change replaces the use of `fallthrough` in the tree with
`HEIM_FALLTHROUGH` and updates the declaration in configure logic
to define `HEIM_FALLTHROUGH` based upon existing definitions
(if any) of `fallthrough` or `DISPATCH_FALLTHROUGH`.
2022-09-16 15:58:45 -04:00
Nicolas Williams
56b60a1a40 asn1: Fix printing of decorated types 2022-03-28 16:18:10 -05:00
Nicolas Williams
db0ba731ca asn1: Allow comments and leading ws in opt files 2022-03-17 17:19:31 -05:00
Jeffrey Altman
19b337a0fb lib/asn1: new ASN1 objects require new exports
free_KERB_AD_RESTRICTION_ENTRY
encode_KERB_AD_RESTRICTION_ENTRY
decode_KERB_AD_RESTRICTION_ENTRY
length_KERB_AD_RESTRICTION_ENTRY
copy_KERB_AD_RESTRICTION_ENTRY

free_PA_KERB_KEY_LIST_REP
encode_PA_KERB_KEY_LIST_REP
decode_PA_KERB_KEY_LIST_REP
length_PA_KERB_KEY_LIST_REP
copy_PA_KERB_KEY_LIST_REP

free_PA_KERB_KEY_LIST_REQ
encode_PA_KERB_KEY_LIST_REQ
decode_PA_KERB_KEY_LIST_REQ
length_PA_KERB_KEY_LIST_REQ
copy_PA_KERB_KEY_LIST_REQ

free_PA_PAC_OPTIONS
encode_PA_PAC_OPTIONS
decode_PA_PAC_OPTIONS
length_PA_PAC_OPTIONS
copy_PA_PAC_OPTIONS

free_PA_S4U_X509_USER
encode_PA_S4U_X509_USER
decode_PA_S4U_X509_USER
length_PA_S4U_X509_USER
copy_PA_S4U_X509_USER

Change-Id: I4ccbfcec64572b41878062e50a61de3f92fdf593
2022-03-03 12:05:14 -05:00
Stefan Metzmacher
d4ac17d6d0 krb5: add new values and definitions from MS-KILE/MS-SFU
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-03-03 10:13:42 +11:00
Nicolas Williams
61607fa6ea asn1: Add a GitHub Markdown manual (more) 2022-02-14 21:07:47 -06:00
Nicolas Williams
dda9aa2535 asn1: Add a GitHub Markdown manual (moar) 2022-02-14 00:05:28 -06:00
Nicolas Williams
a894fc4527 asn1: Add a GitHub Markdown manual 2022-02-12 15:00:59 -06:00
Jeffrey Altman
301b7ce711 Revert "asn1: Fix Windows build"
This reverts commit ff4033eb59.
2022-01-29 00:15:59 -05:00
Nicolas Williams
4748f3a19d asn1: Revert heim_object_t support 2022-01-28 17:24:57 -06:00
Luke Howard
327ec7e75c krb5: use void * instead of heim_object for PAC decoration 2022-01-28 17:24:57 -06:00
Nicolas Williams
a835b9053d lib/asn1: generate_type_free heim_release not heim_retain
Do not leak the object when the intent is to free it.

Introduced by 40d1271094
("asn1: Expand decoration w/ C types")

Change-Id: If8cd502f61d6f9b72118630839525933911c6697
2022-01-28 13:54:16 -05:00
Jeffrey Altman
ee56cb33b2 lib/asn1: prevent wrong size argument warnings
190263bb7a
("assert non-NULL ptrs before calling mem funcs") introduced
two wrong size argument warnings.  These locations are not
errors since the allocation is simply to ensure that the
data pointer is non-NULL; length is zero.

Change-Id: I7b3b58247799a48da3653008c7b6d7fbbbf83e25
2022-01-24 00:31:27 -05:00
Jeffrey Altman
190263bb7a assert non-NULL ptrs before calling mem funcs
The definitions of memcpy(), memmove(), and memset() state that
the behaviour is undefined if any of the pointer arguments are
NULL, and some compilers are known to make use of this to
optimise away existing NULL checks in the source.

Change-Id: I489bc256e3eac7ff41d91becb0b43aba73dbb3f9
Link: https://www.imperialviolet.org/2016/06/26/nonnull.html
2022-01-24 00:07:51 -05:00
Jeffrey Altman
0a17a0b3b7 lib/asn1: der_put_length test 'size' is non-NULL
Change-Id: I1ffbf1998485fdca7cf151c24c440fb0b35e77e4
2022-01-23 21:47:58 -05:00
Jeffrey Altman
38536d7313 lib/asn1: set *size output to zero at start of der funcs
Assign zero to the output size parameter at the start so that
callers that use the value when an error occurs do not see
garbage that might be misinterpreted.

Change-Id: Iccfcf4f6944b1bf72789c83919901d9b9d6f9153
2022-01-23 00:10:14 -05:00
Nicolas Williams
d64076dfd9 asn1: Update commentary on grammar 2022-01-22 03:48:27 -06:00
Nicolas Williams
dfc26ae8c1 asn1: Fix last remaining shift/reduce conflict 2022-01-22 03:48:27 -06:00
Nicolas Williams
e1fa08a4d6 asn1: Fix 5 shift/reduce conflicts
There remains one tough shift/reduce conflict, the warning for which is
quieted with an `%expect 1` directive.

The remaining conflict has to do with whether a constraint attaches to
the inner type that some other outer type is a SET OF or SEQUENCE OF or
tagged-type of, or whether it attaches to the outer type.  The two are
really the same thing.  The latter is the reduce side, so it's not used,
but if it were we could grab the constraint in the action and attach it
to the inner type anyways.
2022-01-21 22:37:05 -06:00
Jeffrey Altman
04527412e3 Follow the Linux kernel's lead on "fallthrough"
The pseudo keyword 'fallthrough' is defined such that case statement
blocks must end with any of these keywords:
 * break;
 * fallthrough;
 * continue;
 * goto <label>;
 * return [expression];
 *
 *  gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes

The macro is defined either as

  __attribute__((__fallthrough__))

or as

  do {} while (0)  /* fallthrough */

not including the semicolon.

This change implements the Linux kernel style and updates several locations
where "/*fallthrough*/ and /* FALLTHROUGH */ were not previously replaced.

Externally imported code such as libedit, libtommath and sqlite are
restored to their unaltered state.

Change-Id: I69db8167b0d5884f55d96d72de3059a0235a1ba3
2022-01-21 10:39:47 -05:00
Joseph Sutton
1c93a6ff26 heimdal: Avoid overflow when performing bitwise shift operations
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-01-18 00:31:45 -05:00
Nicolas Williams
68e2135361 asn1: Fix coverity warnings 2022-01-17 16:00:07 -06:00
Nicolas Williams
a0278f7da2 asn1: Add error checking for open types 2022-01-17 16:00:07 -06:00
Nicolas Williams
9fb444983e asn1: Better handling of >63 named bits/ints
First, we enlarge Member's val field to int64_t.

Then we warn about skipping 2int, int2, and parse units glue for such
things with too-large members.

And we error out when generating the template for such things with
>UINT32_MAX members.

What about too-negative members?  That could be a thing for INTEGER /
ENUMERATED.  We'll look at that later.
2022-01-17 12:39:19 -06:00
Jeffrey Altman
424aa1cb78 lib/asn1: _asn1_print_open_type free 'indents'
'indents' was leaked on one code path.

Change-Id: Ib4a7a8dcf7aae05a79ac6738da3a87a61e85c48e
2022-01-16 22:22:48 -05:00
Nicolas Williams
febdcd4cbd cf: Make clang-format style common makefile macro 2022-01-16 14:07:03 -06:00
Nicolas Williams
fcfd380d15 asn1: Better clang-format / makefile pattern 2022-01-16 13:41:37 -06:00