summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-05-07 16:53:04 +0200
committerHarald Welte <laforge@gnumonks.org>2019-05-10 07:09:29 +0000
commit37db7d3ea6d9f62940b26dc5e9f9457a8c35eced (patch)
treeb39779b99cd025554c3e3de44f190ddceeeb7630
parent76bbcbc19ef28907f514a3bc0fb0846055051969 (diff)
Fix osmo_quote_str_c() for strings larger than 32 bytes
As Neels pointed out, we shouldn't pass a constant value of 32 to osmo_quote_str_buf2(). Change-Id: Id9bde14166d6674ce4dda36fa9f4ae9217ce5cc2
-rw-r--r--src/utils.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c
index b66721e6..59dc8163 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -813,10 +813,21 @@ const char *osmo_quote_str(const char *str, int in_len)
*/
char *osmo_quote_str_c(const void *ctx, const char *str, int in_len)
{
- char *buf = talloc_size(ctx, OSMO_MAX(in_len+2, 32));
+ size_t len = in_len == -1 ? strlen(str) : in_len;
+ char *buf;
+
+ /* account for two quote characters + terminating NUL */
+ len += 3;
+
+ /* some minimum length for things like "NULL" or "(error)" */
+ if (len < 32)
+ len = 32;
+
+ buf = talloc_size(ctx, len);
if (!buf)
return NULL;
- return osmo_quote_str_buf2(buf, 32, str, in_len);
+
+ return osmo_quote_str_buf2(buf, len, str, in_len);
}
/*! perform an integer square root operation on unsigned 32bit integer.