From 583b1de4a5aa3bfae21a4cedb21be1d5e5608d6a Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 8 Jan 2022 23:32:42 +0100 Subject: [PATCH] Fix unterminated string regression --- cs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cs.c b/cs.c index db75c756..5cc9cc96 100644 --- a/cs.c +++ b/cs.c @@ -552,17 +552,18 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI postprinter((csh)handle, insn, buffer, mci); #ifndef CAPSTONE_DIET - char *prefix = strchr (buffer, '|'); + char *prefix = strchr(buffer, '|'); if (prefix) { *prefix = ' '; } - char *tab = strchr (buffer, '\t'); + char *tab = strchr(buffer, '\t'); if (tab) { *tab = 0; } - strncpy (insn->mnemonic, buffer, sizeof (insn->mnemonic) - 1); + strncpy(insn->mnemonic, buffer, sizeof(insn->mnemonic) - 1); if (tab) { - strcpy (insn->op_str, tab + 1); + strncpy(insn->op_str, tab + 1, sizeof(insn->op_str) - 1); + insn->op_str[sizeof(insn->op_str) - 1] = '\0'; } // we might have customized mnemonic