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

Probably a mistake in function der_decode_choice #627

Closed
ParfenovIgor opened this issue Jul 28, 2023 · 1 comment · Fixed by #626
Closed

Probably a mistake in function der_decode_choice #627

ParfenovIgor opened this issue Jul 28, 2023 · 1 comment · Fixed by #626

Comments

@ParfenovIgor
Copy link

core/lib/libtomcrypt/src/pk/asn1/der/choice/der_decode_choice.c

int der_decode_choice(const unsigned char *in,   unsigned long *inlen,
                            ltc_asn1_list *list, unsigned long  outlen)
{
   unsigned long size, x, z;
   void          *data;

   LTC_ARGCHK(in    != NULL);
   LTC_ARGCHK(inlen != NULL);
   LTC_ARGCHK(list  != NULL);

   /* get blk size */
   if (*inlen < 2) {
      return CRYPT_INVALID_PACKET;
   }

   /* set all of the "used" flags to zero */
   for (x = 0; x < outlen; x++) {
       list[x].used = 0;
   }

   /* now scan until we have a winner */
   for (x = 0; x < outlen; x++) {
       size = list[x].size;
       data = list[x].data;

       switch (list[x].type) {
           case LTC_ASN1_BOOLEAN:
               if (der_decode_boolean(in, *inlen, data) == CRYPT_OK) {
                  if (der_length_boolean(&z) == CRYPT_OK) {
                      list[x].used = 1;
                      *inlen       = z;
                      return CRYPT_OK;
                  }
               }
               break;

           case LTC_ASN1_INTEGER:
               if (der_decode_integer(in, *inlen, data) == CRYPT_OK) {
                  if (der_length_integer(data, &z) == CRYPT_OK) {
                      list[x].used = 1;
                      *inlen       = z;
                      return CRYPT_OK;
                  }
               }
               break;

           case LTC_ASN1_SHORT_INTEGER:
               if (der_decode_short_integer(in, *inlen, data) == CRYPT_OK) {
                  if (der_length_short_integer(size, &z) == CRYPT_OK) {
                      list[x].used = 1;
                      *inlen       = z;
                      return CRYPT_OK;
                  }
               }
               break;

Probably, on line if (der_length_short_integer(size, &z) == CRYPT_OK) { there should be data instead of size.

/**
  Gets length of DER encoding of num
  @param num    The integer to get the size of
  @param outlen [out] The length of the DER encoding for the given integer
  @return CRYPT_OK if successful
*/
int der_length_short_integer(unsigned long num, unsigned long *outlen)
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
@sjaeckel sjaeckel linked a pull request Aug 7, 2023 that will close this issue
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
sjaeckel added a commit that referenced this issue Aug 7, 2023
Signed-off-by: Steffen Jaeckel <[email protected]>
@sjaeckel
Copy link
Member

sjaeckel commented Aug 7, 2023

Thanks for reporting this! #626 will fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants