extern size_t riscv_vlen_asm(void);
-static void parse_env(const char *envstr);
-static void strtoupper(char *str);
-
static size_t vlen = 0;
#ifdef OSSL_RISCV_HWPROBE
return 0;
}
-static void strtoupper(char *str)
+static void strtoupper(const char *str, char *dst, size_t dstlen)
{
- for (char *x = str; *x; ++x)
- *x = toupper((unsigned char)*x);
+ for (size_t i = 0; i < dstlen; i++) {
+ if (i == dstlen - 1 || str[i] == '\0') {
+ dst[i] = '\0';
+ break;
+ }
+ dst[i] = toupper((unsigned char)str[i]);
+ }
}
/* parse_env() parses a RISC-V architecture string. An example of such a string
char buf[BUFLEN];
/* Convert env str to all uppercase */
- OPENSSL_strlcpy(envstrupper, envstr, sizeof(envstrupper));
- strtoupper(envstrupper);
+ strtoupper(envstr, envstrupper, sizeof(envstrupper));
for (size_t i = 0; i < kRISCVNumCaps; ++i) {
+ size_t len = strlen(RISCV_capabilities[i].name);
/* Prefix capability with underscore in preparation for search */
- BIO_snprintf(buf, BUFLEN, "_%s", RISCV_capabilities[i].name);
- if (strstr(envstrupper, buf) != NULL) {
- /* Match, set relevant bit in OPENSSL_riscvcap_P[] */
- OPENSSL_riscvcap_P[RISCV_capabilities[i].index] |= (1 << RISCV_capabilities[i].bit_offset);
+ /*
+ * Avoid using higher level library functions which may require
+ * library initialization (such as BIO_snprintf) as this may be called
+ * in a constructor before library initialization
+ */
+ if (len < BUFLEN - 1) {
+ buf[0] = '_';
+ memcpy(buf + 1, RISCV_capabilities[i].name, len);
+ buf[len + 1] = '\0';
+ if (strstr(envstrupper, buf) != NULL) {
+ /* Match, set relevant bit in OPENSSL_riscvcap_P[] */
+ OPENSSL_riscvcap_P[RISCV_capabilities[i].index] |= (1 << RISCV_capabilities[i].bit_offset);
+ }
}
}
}