Summary: | shared: strv can't have more than 4294967295 elements | ||
---|---|---|---|
Product: | systemd | Reporter: | Hristo Venev <hristo> |
Component: | general | Assignee: | systemd-bugs |
Status: | RESOLVED FIXED | QA Contact: | systemd-bugs |
Severity: | normal | ||
Priority: | medium | ||
Version: | unspecified | ||
Hardware: | Other | ||
OS: | All | ||
Whiteboard: | |||
i915 platform: | i915 features: | ||
Bug Depends on: | |||
Bug Blocks: | 76746 | ||
Attachments: | Use size_t for strv size and index |
Description
Hristo Venev
2014-03-28 16:39:33 UTC
Please submit patches to the mailing list, not to Bugzilla. Please ignore the patch and fix the bug. strv is an array of strings, so if we got anywhere close to MAX_UNSIGNED elements we'd be in deep shit anyway. Various algorithms on strv are linear, so using those structures for more than a couple hundred elements would be painful anyway. If you care to provide a patch, then please do so (on the mailing list), but imo current implementation is sufficient. # busctl --host=... OK, we're listing all names. An eternity and a half later: Enter strv_push ...| // n = (1<<32) - 2 402| c = realloc(*l, sizeof(char*) * (n + 2)); ...| // *l is freed, malloc(0) (16 bytes allocated in glibc). ...| ... 406| c[n] = value; ...| Write into unallocated memory Therefore, either strv functions must fail properly if the strv is too large (1<<16 is reasonable) or they must work with sizes up to SIZE_MAX/sizeof(char*). OK, that's a real case. Can you provide an updated patch? Created attachment 107785 [details] [review] Use size_t for strv size and index This is not a complete patch. There probably are a lot more things to fix. I added two overflow checks now for strv_push() and strv_push_prepend() that should protect us if the arrays really grew that much in the first place. Any other place still missing? Thanks for the pointer! |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.