From c3fef9befc63760bd916ae9865669ac9681e0395 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 11 May 2020 16:23:26 -0700 Subject: [PATCH] SCP: Fix expression evaluation of empty string to numeric value Previously, numeric values incorrectly had a string representation of "". This allowed arbitrary equality comparisons to succeed in unexpected ways. Reported by Robert Sancho Villas --- scp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scp.c b/scp.c index d1a1cc8b..0593da6b 100644 --- a/scp.c +++ b/scp.c @@ -15057,6 +15057,7 @@ if (sim_isalpha (*data) || (*data == '_')) { gptr = _sim_get_env_special (data, string, string_size - 1); if (gptr) { *svalue = strtotsv(string, &gptr, 0); + sprint_val (string, *svalue, 10, string_size - 1, PV_LEFTSIGN); sim_debug (SIM_DBG_EXP_EVAL, &sim_scp_dev, "[Value: %s=%s]\n", data, string); return ((*gptr == '\0') && (*string)); } @@ -15072,6 +15073,7 @@ if ((data[0] == '"') && (data_size > 1) && (data[data_size - 1] == '"')) strlcpy (string, data, string_size); if (string[0] == '\0') { *svalue = strtotsv(data, &gptr, 0); + strlcpy (string, data, string_size); sim_debug (SIM_DBG_EXP_EVAL, &sim_scp_dev, "[Value: %s=%s]\n", data, string); return ((*gptr == '\0') && (*data)); }