Skip to content

Commit 3704215

Browse files
jpnurmiclaude
andcommitted
fix(tracing): use locale-independent isalnum in baggage encoder
`isalnum` from `<ctype.h>` is locale-dependent: in non-"C" locales (e.g. ISO-8859-1) bytes > 127 — such as UTF-8 continuation bytes in release / environment values — can be classified as alphanumeric and left unencoded, producing a malformed baggage header. RFC 3986's `unreserved` set is strict ASCII by definition, so replace the call with a small locale-independent ASCII-range helper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0a49a1e commit 3704215

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/sentry_tracing.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include <stdio.h>
1414
#include <string.h>
1515

16+
static inline bool
17+
isalnum_c(unsigned char c)
18+
{
19+
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')
20+
|| (c >= 'a' && c <= 'z');
21+
}
22+
1623
static void
1724
percent_encode_append(sentry_stringbuilder_t *sb, const char *value)
1825
{
@@ -21,7 +28,7 @@ percent_encode_append(sentry_stringbuilder_t *sb, const char *value)
2128
static const char hex[] = "0123456789ABCDEF";
2229
for (const unsigned char *p = (const unsigned char *)value; *p; p++) {
2330
unsigned char c = *p;
24-
if (isalnum(c) || c == '-' || c == '.' || c == '_' || c == '~') {
31+
if (isalnum_c(c) || c == '-' || c == '.' || c == '_' || c == '~') {
2532
sentry__stringbuilder_append_char(sb, (char)c);
2633
} else {
2734
char esc[3] = { '%', hex[c >> 4], hex[c & 0xF] };

0 commit comments

Comments
 (0)