mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
Merge pull request #29315 from poettering/strgrowpad0
string-util: make strgrowpad0() safer
This commit is contained in:
@@ -627,14 +627,23 @@ char* strshorten(char *s, size_t l) {
|
||||
}
|
||||
|
||||
int strgrowpad0(char **s, size_t l) {
|
||||
size_t sz;
|
||||
|
||||
assert(s);
|
||||
|
||||
if (*s) {
|
||||
sz = strlen(*s) + 1;
|
||||
if (sz >= l) /* never shrink */
|
||||
return 0;
|
||||
} else
|
||||
sz = 0;
|
||||
|
||||
char *q = realloc(*s, l);
|
||||
if (!q)
|
||||
return -ENOMEM;
|
||||
|
||||
*s = q;
|
||||
|
||||
size_t sz = strlen(*s);
|
||||
memzero(*s + sz, l - sz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4159,6 +4159,9 @@ static int partition_format_verity_sig(Context *context, Partition *p) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format verity signature JSON object: %m");
|
||||
|
||||
if (strlen(text)+1 > p->new_size)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(E2BIG), "Verity signature too long for partition: %m");
|
||||
|
||||
r = strgrowpad0(&text, p->new_size);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to pad string to %s", FORMAT_BYTES(p->new_size));
|
||||
|
||||
Reference in New Issue
Block a user