version 1.3, 2019/08/11 15:52:46 |
version 1.4, 2019/10/09 05:44:06 |
|
|
size_t len, i; |
size_t len, i; |
long long v, ticks; |
long long v, ticks; |
int d; |
int d; |
int is_hex = 0; |
int is_hex = 0, ret; |
struct ber_oid o; |
struct ber_oid o; |
char strbuf[BUFSIZ]; |
char strbuf[BUFSIZ]; |
char *hint; |
char *hint; |
|
|
* hex is 3 * n (2 digits + n - 1 spaces + NUL-byte) |
* hex is 3 * n (2 digits + n - 1 spaces + NUL-byte) |
* ascii can be max (2 * n) + 2 quotes + NUL-byte |
* ascii can be max (2 * n) + 2 quotes + NUL-byte |
*/ |
*/ |
if ((p = str = reallocarray(NULL, |
len = output_string == smi_os_hex ? 3 : 2; |
output_string == smi_os_hex ? 3 : 2, |
p = str = reallocarray(NULL, root->be_len + 2, len); |
root->be_len + 2)) == NULL) |
if (p == NULL) |
goto fail; |
goto fail; |
if (is_hex) |
len *= root->be_len + 2; |
|
if (is_hex) { |
*str++ = '"'; |
*str++ = '"'; |
|
len--; |
|
} |
for (i = 0; i < root->be_len; i++) { |
for (i = 0; i < root->be_len; i++) { |
switch (output_string) { |
switch (output_string) { |
case smi_os_default: |
case smi_os_default: |
|
|
* There's probably more edgecases here, |
* There's probably more edgecases here, |
* not fully investigated |
* not fully investigated |
*/ |
*/ |
if (is_hex && buf[i] == '\\') |
if (len < 2) |
|
goto fail; |
|
if (is_hex && buf[i] == '\\') { |
*str++ = '\\'; |
*str++ = '\\'; |
|
len--; |
|
} |
*str++ = isprint(buf[i]) ? buf[i] : '.'; |
*str++ = isprint(buf[i]) ? buf[i] : '.'; |
|
len--; |
break; |
break; |
case smi_os_hex: |
case smi_os_hex: |
sprintf(str, "%s%02hhX", |
ret = snprintf(str, len, "%s%02hhX", |
i == 0 ? "" : |
i == 0 ? "" : |
i % 16 == 0 ? "\n" : " ", buf[i]); |
i % 16 == 0 ? "\n" : " ", buf[i]); |
str += i == 0 ? 2 : 3; |
if (ret == -1 || ret > (int) len) |
|
goto fail; |
|
len -= ret; |
|
str += ret; |
break; |
break; |
} |
} |
} |
} |
if (is_hex) |
if (is_hex) { |
|
if (len < 2) |
|
goto fail; |
*str++ = '"'; |
*str++ = '"'; |
|
len--; |
|
} |
|
if (len == 0) |
|
goto fail; |
*str = '\0'; |
*str = '\0'; |
str = NULL; |
str = NULL; |
if (asprintf(&str, "%s%s", |
if (asprintf(&str, "%s%s", |