I think here is a bug:
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)); if (!buf) return NULL; return osmo_quote_str_buf2(buf, 32, str, in_len); }
We may allocate more than 32 bytes (see OSMO_MAX()) but still allow to write only 32 bytes?
Looks like the allocated len should be stored in a local variable to pass to osmo_quote_str_buf2().
And if I'm right, what is the 32 for? At least 32??
~N
Hi Neels,
I don't quite get why is 32 used there. Also documentation and implementation look wrong to me: * doc talks about static buffer. That makes no sense to me, line should be removed. * Case of in_len=-1 is not correctly handled there.
I'd change it to:
char *osmo_quote_str_c(const void *ctx, const char *str, int in_len) { size_t len = in_len == -1 ? strlen(str) : in_len; len += 2; char *buf = talloc_size(ctx, len); if (!buf) return NULL; return osmo_quote_str_buf2(buf, len, str, in_len); }
Hi Neels,
On Fri, Apr 12, 2019 at 03:23:41AM +0200, Neels Hofmeyr wrote:
I think here is a bug:
ACK.
Looks like the allocated len should be stored in a local variable to pass to osmo_quote_str_buf2().
ACK. See https://gerrit.osmocom.org/#/c/libosmocore/+/13901
And if I'm right, what is the 32 for? At least 32??
At least 32 bytes to have some minimum buffer size for things like printing "NULL" or the like.