mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
util-lib: [static] array argument sizes are apparently not OK for NULL parameters
Let's drop the 'static' logic when a parameter can be NULL. I think asan/ubsan are right here, judging by the C99 spec language: "A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression." If we specify NULL, then we certainly don't pvode access to any valid array. Fixes: #13039
This commit is contained in:
parent
f90bcf8679
commit
6fb0569065
@ -725,10 +725,17 @@ char *strreplace(const char *text, const char *old_string, const char *new_strin
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void advance_offsets(ssize_t diff, size_t offsets[static 2], size_t shift[static 2], size_t size) {
|
||||
static void advance_offsets(
|
||||
ssize_t diff,
|
||||
size_t offsets[2], /* note: we can't use [static 2] here, since this may be NULL */
|
||||
size_t shift[static 2],
|
||||
size_t size) {
|
||||
|
||||
if (!offsets)
|
||||
return;
|
||||
|
||||
assert(shift);
|
||||
|
||||
if ((size_t) diff < offsets[0])
|
||||
shift[0] += size;
|
||||
if ((size_t) diff < offsets[1])
|
||||
@ -844,8 +851,7 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
|
||||
|
||||
fclose(f);
|
||||
|
||||
free(*ibuf);
|
||||
*ibuf = obuf;
|
||||
free_and_replace(*ibuf, obuf);
|
||||
|
||||
if (_isz)
|
||||
*_isz = osz;
|
||||
@ -855,7 +861,7 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
|
||||
highlight[1] += shift[1];
|
||||
}
|
||||
|
||||
return obuf;
|
||||
return *ibuf;
|
||||
}
|
||||
|
||||
char *strextend_with_separator(char **x, const char *separator, ...) {
|
||||
|
Loading…
Reference in New Issue
Block a user