[collectd] notify_email plugin
Sebastian Harl
sh at tokkee.org
Wed Jun 4 13:29:04 CEST 2008
Hi Oleg,
On Wed, Jun 04, 2008 at 03:05:01PM +0400, Oleg King wrote:
> >> if ( !(message = smtp_add_message (session))) {
> >> ERROR ("notify_email plugin: cannot set SMTP message");
> >> return (-1);
> > Don't you have to destroy the session, etc. before you return from the
> > function in case of an error?
>
> Yes, this is exactly as example from libesmtp does. libesmtp has
> documented approx. half of its functions, and workflow exists only in
> example file. So I think nobody knows it for sure :)
Hmkay... I'm pretty sure that each create- or init-function comes along
with a matching destroy- or similar function which imho should be called
in any case - else memory might leak.
> >> static int notify_email_notification (const notification_t *n)
> > [...]
> >> sprintf (subject, smtp_subject == NULL ? DEFAULT_SMTP_SUBJECT : smtp_subject, severity, n->host);
>
> > While this is a really nice feature, it requires some input validation.
> > Image the user specifies more than two conversion specifications
> > (%somethings) - then random memory is read to fetch subsequent
> > parameters which is really not what we want. Also, the verification
> > should check if a string (%s) has been specified.
>
> As I know sprintf should not do substitutions more than number of
> arguments and more then number of %something.
Well, short answer: no.
Somewhat longer answer: Any %something usually consumes on ore more
arguments (usually just one, but there are some rare cases where more
than one argument may be consumed). So, the number of consumed arguments
is _only_ determined by the number of %somethings. The printf function
does not know how many arguments have actually been passed to it, so it
will happily (try to) read further arguments until it processed all
%somethings. So, if there are more %somethings than actual arguments,
printf will read random memory and possibly segfault when trying to do
so.
HTH,
Sebastian
--
Sebastian "tokkee" Harl +++ GnuPG-ID: 0x8501C7FC +++ http://tokkee.org/
Those who would give up Essential Liberty to purchase a little Temporary
Safety, deserve neither Liberty nor Safety. -- Benjamin Franklin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080604/3b9f9011/attachment.pgp
More information about the collectd
mailing list