eclair: use snprintf instead of sprintf to prevent buffer-overrun

Change-Id: I2a27cffe303201e1738f115258f6e02058dbc63d
Refs: #1356
Fujitsu: POSTK_DEBUG_ARCH_DEP_38
This commit is contained in:
Ken Sato
2019-09-09 15:09:10 +09:00
committed by Masamichi Takagi
parent beac6c3e80
commit a4b83dc6d4
5 changed files with 267 additions and 8 deletions

View File

@@ -678,7 +678,6 @@ static ssize_t print_hex(char *buf, size_t buf_size, char *str) {
q = buf;
for (p = str; *p != '\0'; ++p) {
#ifdef POSTK_DEBUG_ARCH_DEP_38
int ret;
ret = snprintf(q, buf_size, "%02x", *p);
@@ -687,9 +686,6 @@ static ssize_t print_hex(char *buf, size_t buf_size, char *str) {
}
q += ret;
buf_size -= ret;
#else /* POSTK_DEBUG_ARCH_DEP_38 */
q += sprintf(q, "%02x", *p);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
}
*q = '\0';
@@ -704,7 +700,6 @@ ssize_t print_bin(char *buf, size_t buf_size, void *data, size_t size) {
p = data;
q = buf;
for (i = 0; i < size; ++i) {
#ifdef POSTK_DEBUG_ARCH_DEP_38
int ret;
ret = snprintf(q, buf_size, "%02x", *p);
@@ -713,9 +708,6 @@ ssize_t print_bin(char *buf, size_t buf_size, void *data, size_t size) {
}
q += ret;
buf_size -= ret;
#else /* POSTK_DEBUG_ARCH_DEP_38 */
q += sprintf(q, "%02x", *p);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
++p;
}
*q = '\0';