mirror of
https://github.com/systemd/systemd.git
synced 2026-07-13 19:10:58 +00:00
string-util: allow taking SIZE_MAX as size to shorten to
This is useful for two reasons: 1. it addresses a potential overflow in a graceful way 2. Gives callers the ability to just pass SIZE_MAX for a NOP Prompted by: #31341
This commit is contained in:
committed by
Luca Boccassi
parent
10d50d9eac
commit
d49dc7bbe7
@@ -620,6 +620,9 @@ char *cellescape(char *buf, size_t len, const char *s) {
|
||||
char* strshorten(char *s, size_t l) {
|
||||
assert(s);
|
||||
|
||||
if (l >= SIZE_MAX-1) /* Would not change anything */
|
||||
return s;
|
||||
|
||||
if (strnlen(s, l+1) > l)
|
||||
s[l] = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user