Merge pull request #8600 from keszybz/oss-fuzz-again

Fuzzing- and test-related fixes
This commit is contained in:
Lennart Poettering 2018-03-28 13:01:37 +02:00 committed by GitHub
commit ce9aa31496
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 18 deletions

View file

@ -2478,7 +2478,7 @@ finish:
* in become_shutdown() so normally we cannot free them yet. */
watchdog_free_device();
arg_watchdog_device = mfree(arg_watchdog_device);
return 0;
return retval;
}
#endif

View file

@ -46,7 +46,7 @@
#define POSSIBLE_SPECIFIERS ALPHANUMERICAL "%"
int specifier_printf(const char *text, const Specifier table[], void *userdata, char **_ret) {
size_t l;
size_t l, allocated = 0;
_cleanup_free_ char *ret = NULL;
char *t;
const char *f;
@ -57,14 +57,11 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
assert(table);
l = strlen(text);
ret = new(char, l+1);
if (!ret)
if (!GREEDY_REALLOC(ret, allocated, l + 1))
return -ENOMEM;
t = ret;
for (f = text; *f; f++, l--) {
for (f = text; *f; f++, l--)
if (percent) {
if (*f == '%')
*(t++) = '%';
@ -77,7 +74,6 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
if (i->lookup) {
_cleanup_free_ char *w = NULL;
char *n;
size_t k, j;
r = i->lookup(i->specifier, i->data, userdata, &w);
@ -87,14 +83,9 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
j = t - ret;
k = strlen(w);
n = new(char, j + k + l + 1);
if (!n)
if (!GREEDY_REALLOC(ret, allocated, j + k + l + 1))
return -ENOMEM;
memcpy(n, ret, j);
memcpy(n + j, w, k);
free_and_replace(ret, n);
memcpy(ret + j, w, k);
t = ret + j + k;
} else if (strchr(POSSIBLE_SPECIFIERS, *f))
/* Oops, an unknown specifier. */
@ -110,13 +101,19 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
percent = true;
else
*(t++) = *f;
}
/* if string ended with a stray %, also end with % */
/* If string ended with a stray %, also end with % */
if (percent)
*(t++) = '%';
*(t++) = 0;
/* Try to deallocate unused bytes, but don't sweat it too much */
if ((size_t)(t - ret) < allocated) {
t = realloc(ret, t - ret);
if (t)
ret = t;
}
*t = 0;
*_ret = TAKE_PTR(ret);
return 0;
}

File diff suppressed because one or more lines are too long