Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #106248
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: openssh do_log function has larger than needed buffer? |
| Date | 2017-03-16 14:25 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <874lytti14.fsf@bsb.me.uk> (permalink) |
| References | <chx8to6l3qh.fsf@iceland.freeshell.org> |
Mike Small <smallm@sdf.org> writes: > I was looking at a function in OpenSSH that prepares a string for > logging and calls syslog with a format string limiting the length of > what is written. I'm puzzled by the difference between the size of the > char array used to compose the string (1024 bytes) and the limit on the > number of its characters that could be output by syslog (format > specifier "%.500s"). It looks like maybe a hang-over from when the code had hand-coded sizes. Or maybe there was a reason to further limit the logging via routes? Hard to say. > The only potential explanation I could think of was that it might have > something to do with multibyte strings, that maybe a string could be > devised such that the buffer would overrun from use of characters > encoded by more than one byte. But looking at the function calls before > the syslog call I'm thinking the string should be guaranteed to be nul > terminated, which I think prevents overrun even if there are multibyte > characters included. Yup. It can't be that. I think it's just an accident. But if you want a belt-and-braces approach, put a null at the end of the array just before using %s and you can be sure the logging function won't read beyond that. <snip> -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
openssh do_log function has larger than needed buffer? Mike Small <smallm@sdf.org> - 2017-03-15 19:49 +0000 Re: openssh do_log function has larger than needed buffer? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-16 14:25 +0000
csiph-web