Browse Source

improve `pk_oid_num_to_str()`

* allow `OID` to be `NULL` until you want to write it ...
* make sure we don't overflow the `int i`

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 3 years ago
parent
commit
5c30a53074
1 changed files with 2 additions and 1 deletions
  1. 2 1
      src/pk/asn1/oid/pk_oid_str.c

+ 2 - 1
src/pk/asn1/oid/pk_oid_str.c

@@ -49,7 +49,7 @@ int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID,
    char tmp[256] = { 0 };
    char tmp[256] = { 0 };
 
 
    LTC_ARGCHK(oid != NULL);
    LTC_ARGCHK(oid != NULL);
-   LTC_ARGCHK(OID != NULL);
+   LTC_ARGCHK(oidlen < INT_MAX);
    LTC_ARGCHK(outlen != NULL);
    LTC_ARGCHK(outlen != NULL);
 
 
    for (i = oidlen - 1, k = 0; i >= 0; i--) {
    for (i = oidlen - 1, k = 0; i >= 0; i--) {
@@ -74,6 +74,7 @@ int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID,
       *outlen = k + 1;
       *outlen = k + 1;
       return CRYPT_BUFFER_OVERFLOW;
       return CRYPT_BUFFER_OVERFLOW;
    }
    }
+   LTC_ARGCHK(OID != NULL);
    for (j = 0; j < k; j++) OID[j] = tmp[k - j - 1];
    for (j = 0; j < k; j++) OID[j] = tmp[k - j - 1];
    OID[k] = '\0';
    OID[k] = '\0';
    *outlen = k; /* the length without terminating NUL byte */
    *outlen = k; /* the length without terminating NUL byte */