[systemd-devel] [PATCH 2/2] journal: get rid of LINE_MAX in sd_journal_printv*()
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Mon Apr 15 14:21:03 PDT 2013
On Mon, Apr 15, 2013 at 10:17:45PM +0200, Harald Hoyer wrote:
> Am 15.04.2013 21:29, schrieb Zbigniew Jędrzejewski-Szmek:
> > On Mon, Apr 15, 2013 at 06:41:52PM +0200, harald at redhat.com wrote:
> >> From: Harald Hoyer <harald at redhat.com>
> >>
> >> use stack_size_guess() to get rid of LINE_MAX
> >> ---
> >> src/journal/journal-send.c | 99 +++++++++++++++++++++++++++++++----------
> >> src/journal/test-journal-send.c | 92 +++++++++++++++++++++++++++++++++-----
> >> 2 files changed, 156 insertions(+), 35 deletions(-)
> >>
> >> diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
> >> index 4b9109a..2ff04b4 100644
> >> --- a/src/journal/journal-send.c
> >> +++ b/src/journal/journal-send.c
> >> @@ -26,6 +26,7 @@
> >> #include <unistd.h>
> >> #include <fcntl.h>
> >> #include <printf.h>
> >> +#include <sys/resource.h>
> >>
> >> #define SD_JOURNAL_SUPPRESS_LOCATION
> >>
> >> @@ -35,15 +36,17 @@
> >>
> >> #define SNDBUF_SIZE (8*1024*1024)
> >>
> >> -#define ALLOCA_CODE_FUNC(f, func) \
> >> - do { \
> >> - size_t _fl; \
> >> - const char *_func = (func); \
> >> - char **_f = &(f); \
> >> - _fl = strlen(_func) + 1; \
> >> - *_f = alloca(_fl + 10); \
> >> - memcpy(*_f, "CODE_FUNC=", 10); \
> >> - memcpy(*_f + 10, _func, _fl); \
> >> +#define ALLOCA_CODE_FUNC(f, func) \
> >> + do { \
> >> + size_t _fl; \
> >> + const char *_func = (func); \
> >> + char **_f = &(f); \
> >> + _fl = strlen(_func) + 1; \
> >> + if (stack_size_guess() < (_fl + 10)) \
> > Can't _fl + 10 overflow (on 32 bit)?
>
> You mean signed vs unsigned?
No, I mean _fl can be 4×2³² - 9, and, then _fl+10 == 1.
C99 says size_t is "at least 16 bits", although I don't
think that less than 32 bits is common.
On a modern machine strlen() on a 4GB string should take
about a second, so it seems plausible to feed this function
with a big enough string, maybe on a kernel with PAE.
Zbyszek
More information about the systemd-devel
mailing list