monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SIGSEGV, Segmentation fault.


From: Igor Homyakov
Subject: Re: SIGSEGV, Segmentation fault.
Date: Wed, 21 May 2003 14:05:22 +0400
User-agent: Mutt/1.4.1i

man vsnprintf from my system (glibc-2.2.6)
   Return value
       Upon successful return, these functions return the number of characters
       printed  (not  including  the  trailing  '\0'  used  to  end  output to
       strings).  The functions snprintf and vsnprintf do not write more  than
       size  bytes (including the trailing '\0').  If the output was truncated
       due to this limit then the return value is  the  number  of  characters
       (not  including the trailing '\0') which would have been written to the
       final string if enough space had been available. Thus, a  return  value
       of  size  or  more means that the output was truncated. (See also below
       under NOTES.)  If an output error is encountered, a negative  value  is
       returned.

my GDB log:
(gdb) n
122       va_start(ap,format);
(gdb) n
123       rc = vsnprintf(msg, STRLEN, format, ap);
(gdb) n
126       if(! Run.dolog) goto nolog;
(gdb) print rc
$1 = 22

* Jan-Henrik Haukeland <hauk @ tildeslash.com> [030521 02:17]:
> I'm not sure and I may be wrong, but from the top of my head I do not think
> this is a buffer-size problem i.e. it's not necessary to add 1 byte to the
> buffer when snprintf is used. The buffer is not going to get overrun and
> snprintf adds a '\0' char at the end of the buffer. The man page for *printf
> says:

>    sprintf  stores the output in the specified char array str
>    and snprintf limits number of characters written to str to
>    at  most  size (including terminating 0)...

> And as you can see in the strange string Igor got when he ran gdb,  the NUL
> char was added, the rest of the garble is normal (probably) since the string
> was uninitialized. It seems that the problem is vsnprintf and it fails (with
> malloc!?) because it has problems with the format string? Again from the man
> page:

>   For sprintf and snprintf, the behavior is also  undefined  if  the  output
>   *<[str>>  overlaps with one of the arguments.

> Undefined behaviour usually means SIGSEGV :-) So my two cents are on the
> vsnprintf statement and on the format argument. (I'm on windows right now and
> helping my brother building a house in another town so I cannot check the 
> patch
> right now, but I'll be back next week).


-- 
Igor Homyakov
<homyakov AT ramax.spb.ru>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]