An issue in strcat manpage

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

 



Dear Maintener,

The example illustrating the strcat function man page produces a
buffer owerflow (off-by-one
error). A typical trap of strcat.

The program below shows the problem:

#include <string.h>
#include <stdio.h>

       int
       main(int argc, char *argv[])
       {
       #define LIM 4
           char p[LIM];
       int j ;

           p[0] = '\0';

           for (j = 0; j < LIM; j++)
               strcat(p, "a");
       printf("(j=%d)  p='%s' -- psize : %d  -- plen=%u\n", j,p,LIM,
(unsigned int) strlen(p)) ;

           return 0 ;
       }

Execution:

$ prog
(j=4)  p='aaaa' -- psize : 4 -- plen=4
$

p should be 'aaa'.

Do you intend to fix this issue ?

Yours truly,

Eric Sanchis
Associate Professor in Computer Science
University of Toulouse Capitole (IUT Rodez)
France



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux