Change in libosmocore[master]: Fix osmo_quote_str_c() for strings larger than 32 bytes

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri May 10 07:09:30 UTC 2019


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/13901 )

Change subject: Fix osmo_quote_str_c() for strings larger than 32 bytes
......................................................................

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
---
M src/utils.c
1 file changed, 13 insertions(+), 2 deletions(-)

Approvals:
  Pau Espin Pedrol: Looks good to me, approved
  Mykola Shchetinin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/utils.c b/src/utils.c
index b66721e..59dc816 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -813,10 +813,21 @@
  */
 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.

-- 
To view, visit https://gerrit.osmocom.org/13901
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id9bde14166d6674ce4dda36fa9f4ae9217ce5cc2
Gerrit-Change-Number: 13901
Gerrit-PatchSet: 6
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Mykola Shchetinin <mykola at pentonet.com>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190510/f813b8ba/attachment.htm>


More information about the gerrit-log mailing list