Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asn1: Regenerate ASN.1 code using newer version of asn1c #7066

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

abbra
Copy link
Contributor

@abbra abbra commented Oct 26, 2023

No description provided.

@abbra
Copy link
Contributor Author

abbra commented Oct 26, 2023

@simo5 could you please look at this when you have some time?

I generated new code using current asn1c git master branch.

@abbra abbra added the re-run Trigger a new run of PR-CI label Oct 26, 2023
@freeipa-pr-ci freeipa-pr-ci removed the re-run Trigger a new run of PR-CI label Oct 26, 2023
sphinx will change defaults for HTML scheme, enforce existing behavior.

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
v0.9.29 (unreleased) has several improvements that we wanted to apply,
mostly in memory management.

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
@abbra abbra added the re-run Trigger a new run of PR-CI label Oct 27, 2023
@freeipa-pr-ci freeipa-pr-ci removed the re-run Trigger a new run of PR-CI label Oct 27, 2023
@abbra
Copy link
Contributor Author

abbra commented Oct 27, 2023

Ok, I think I picked up all the changes now. Compilation is clean except this one:

INTEGER.c: In function 'asn_imax2INTEGER':
INTEGER.c:977:29: warning: array subscript 0 is outside array bounds of 'intmax_t[1]' [-Warray-bounds=]
  977 |         for(bp = buf, pend1 += add; p != pend1; p += add)
      |                       ~~~~~~^~~~~~
INTEGER.c:933:42: note: at offset -1 into object 'value' of size 8
  933 | asn_imax2INTEGER(INTEGER_t *st, intmax_t value) {
      |                                 ~~~~~~~~~^~~~~

this is coming from a removal of unreferenced pstart in asn1c skeleton:

commit 7e0ab8821dc0ea70307bae73ce29101fc944c5c2
Author: Lev Walkin <vlm@lionet.info>
Date:   Wed Jun 28 08:47:47 2017 -0700

    remove unreferenced var

diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c
index eed82176..b6ab489f 100644
--- a/skeletons/INTEGER.c
+++ b/skeletons/INTEGER.c
@@ -924,7 +924,7 @@ asn_long2INTEGER(INTEGER_t *st, long value) {
                break;
        }
        /* Copy the integer body */
-       for(pstart = p, bp = buf, pend1 += add; p != pend1; p += add)
+       for(bp = buf, pend1 += add; p != pend1; p += add)
                *bp++ = *p;
 
        if(st->buf) FREEMEM(st->buf);

@jrisc
Copy link
Contributor

jrisc commented Oct 30, 2023

The goal of the asn_imax2INTEGER() function is to encode a intmax_t value, whose endianness is architecture-dependent to ASN.1 encoding which uses big endian. In case the local machine is little endian, the program will go though each byte of the intmax_t integer in the reverse order to reverse its endianness. Hence, first ASN.1 byte pstart is set with the last byte of value, the last ASN.1 byte pend1 is set with the first byte of value, and the step add is set with -1 (since pstart > pend1 in this mode).

Line 938 from asn1/asn1c/INTEGER.c

        int littleEndian = 1;   /* Run-time detection */
        int add;

        /* ... */

        if(*(char *)&littleEndian) {
                pstart = (uint8_t *)&value + sizeof(value) - 1;
                pend1 = (uint8_t *)&value;
                add = -1;
        } else {

When initializing the loop, pend1 is moved to the first byte address before value in case the local machine is little endian, causing the scan to happen in a reversed way. This is for the p != pend1 condition to be met at the right point.

Line 976 from asn1/asn1c/INTEGER.c

        /* Copy the integer body */
        for(bp = buf, pend1 += add; p != pend1; p += add)
                *bp++ = *p;

This compilation error seems to be caused by the fact the semantic analyzer still has a logical connection between pend1 and value, because even if they have a different type, they are pointing to the same address in little endian mode:

pend1 = (uint8_t *)&value;

For this reason, the analyzer probably considers that an increment of pend1 should only be positive.

We can either decide to ignore this warning, or try to make it disappear by modifying the loop this way:

for(bp = buf; p != (pend1 + add); p += add)
        *bp++ = *p;

@abbra
Copy link
Contributor Author

abbra commented Nov 1, 2023

Thank you, @jrisc. A bit of update: I ran OpenScanHub over the changes and now am working on the fixes, if any are needed. There are too many false-positives so far as the code is complex for covscan to process.

Copy link

stale bot commented Mar 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PR [Bot] label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale PR [Bot]
Projects
None yet
3 participants