mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
Add more assertions to esc_for_log to please the clangalyzer.
This commit is contained in:
parent
07a16b3372
commit
9b850f9200
1 changed files with 7 additions and 0 deletions
|
@ -1208,9 +1208,14 @@ esc_for_log(const char *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tor_assert(len <= SSIZE_MAX);
|
||||||
|
|
||||||
result = outp = tor_malloc(len);
|
result = outp = tor_malloc(len);
|
||||||
*outp++ = '\"';
|
*outp++ = '\"';
|
||||||
for (cp = s; *cp; ++cp) {
|
for (cp = s; *cp; ++cp) {
|
||||||
|
/* This assertion should always succeed, since we will write at least
|
||||||
|
* one char here, and two chars for closing quote and nul later */
|
||||||
|
tor_assert((outp-result) < (ssize_t)len-2);
|
||||||
switch (*cp) {
|
switch (*cp) {
|
||||||
case '\\':
|
case '\\':
|
||||||
case '\"':
|
case '\"':
|
||||||
|
@ -1234,6 +1239,7 @@ esc_for_log(const char *s)
|
||||||
if (TOR_ISPRINT(*cp) && ((uint8_t)*cp)<127) {
|
if (TOR_ISPRINT(*cp) && ((uint8_t)*cp)<127) {
|
||||||
*outp++ = *cp;
|
*outp++ = *cp;
|
||||||
} else {
|
} else {
|
||||||
|
tor_assert((outp-result) < (ssize_t)len-4);
|
||||||
tor_snprintf(outp, 5, "\\%03o", (int)(uint8_t) *cp);
|
tor_snprintf(outp, 5, "\\%03o", (int)(uint8_t) *cp);
|
||||||
outp += 4;
|
outp += 4;
|
||||||
}
|
}
|
||||||
|
@ -1241,6 +1247,7 @@ esc_for_log(const char *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tor_assert((outp-result) <= (ssize_t)len-2);
|
||||||
*outp++ = '\"';
|
*outp++ = '\"';
|
||||||
*outp++ = 0;
|
*outp++ = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue