Thanks Li and Daniel. The fix has been merged.

Regards--
Subrata

On Mon, 2008-10-20 at 10:17 +0800, Li Zefan wrote:
> Subrata Modak wrote:
> > On Fri, Oct 17, 2008 at 7:58 PM, Daniel Gollub <[EMAIL PROTECTED]> wrote:
> > 
> >> Hi,
> >>
> >> with GCC 4.3 and with LTP CVS snapshot from today i got following warning
> >> when
> >> using the GCC Object Checking Builtins:
> >>
> >>
> >> cc -O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -g
> >> -Wall -O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -g
> >> -I../../../../include -Wall    pec_listener.c  -L../../../../lib -lltp -o
> >> pec_listener
> >> In function 'memset',
> >>       inlined from 'netlink_recv' at pec_listener.c:112,
> >>           inlined from 'main' at pec_listener.c:270:
> >>           /usr/include/bits/string3.h:85: warning: call to
> >> __builtin___memset_chk will always overflow destination buffer
> > 
> > 
> > Li,
> > 
> > Your comment on this ?
> > 
> 
> It's not a correct fix, the patch initializes the message header only.
> Below is a correct one:
> 
> 
> Allocate a buffer large enough to hold NLMSG_SPACE(MAX_MSG_SIZE).
> 
> Signed-off-by: Li Zefan <[EMAIL PROTECTED]>
> ---
>  pec_listener.c |   26 ++++++++++++--------------
>  1 file changed, 12 insertions(+), 14 deletions(-)
> 
> --- a/testcases/kernel/connectors/pec/pec_listener.c  2008-10-20 
> 09:57:39.000000000 +0800
> +++ b/testcases/kernel/connectors/pec/pec_listener.c  2008-10-20 
> 10:09:23.000000000 +0800
> @@ -44,6 +44,8 @@ static __u32 seq;
>  static int exit_flag;
>  static struct sigaction sigint_action;
> 
> +struct nlmsghdr *nlhdr;
> +
>  /*
>   * Handler for signal int. Set exit flag.
>   *
> @@ -64,14 +66,10 @@ static void sigint_handler(int __attribu
>  static int netlink_send(int sd, struct sockaddr_nl *to, struct cn_msg *cnmsg)
>  {
>       int ret;
> -     char buf[MAX_MSG_SIZE];
> -     struct nlmsghdr *nlhdr;
>       struct iovec iov;
>       struct msghdr msg;
> 
> -     memset(buf, 0, MAX_MSG_SIZE);
> -
> -     nlhdr = (struct nlmsghdr *)buf;
> +     memset(nlhdr, 0, NLMSG_SPACE(MAX_MSG_SIZE));
> 
>       nlhdr->nlmsg_seq = seq++;
>       nlhdr->nlmsg_pid = getpid();
> @@ -100,12 +98,10 @@ static int netlink_send(int sd, struct s
>   *
>   * @sd: socket descripor
>   * @from: source sockaddr
> - * @buf: buffer for storing the package
>   */
> -static int netlink_recv(int sd, struct sockaddr_nl *from, char *buf)
> +static int netlink_recv(int sd, struct sockaddr_nl *from)
>  {
>       int ret;
> -     struct nlmsghdr *nlhdr = (struct nlmsghdr *)buf;
>       struct iovec iov;
>       struct msghdr msg;
> 
> @@ -214,14 +210,18 @@ int main(int argc, char **argv)
>       int sd;
>       struct sockaddr_nl l_local;
>       struct sockaddr_nl src_addr;
> -     char buf[MAX_MSG_SIZE];
>       struct pollfd pfd;
> 
>       sigint_action.sa_flags = SA_ONESHOT;
>       sigint_action.sa_handler = &sigint_handler;
>       sigaction(SIGINT, &sigint_action, NULL);
> 
> -     /* Create and bind socket */
> +     nlhdr = malloc(NLMSG_SPACE(MAX_MSG_SIZE));
> +     if (!nlhdr) {
> +             fprintf(stderr, "lack of memory\n");
> +             exit(1);
> +     }
> +
>       sd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
>       if (sd == -1) {
>               fprintf(stderr, "failed to create socket\n");
> @@ -257,7 +257,6 @@ int main(int argc, char **argv)
>       pfd.events = POLLIN;
>       pfd.revents = 0;
>       while (!exit_flag) {
> -             struct nlmsghdr *nlhdr;
> 
>               ret = poll(&pfd, 1, -1);
>               if (ret == 0 || (ret == -1 && errno != EINTR)) {
> @@ -267,7 +266,7 @@ int main(int argc, char **argv)
>               } else if (ret == -1 && errno == EINTR)
>                       break;
> 
> -             ret = netlink_recv(sd, &src_addr, buf);
> +             ret = netlink_recv(sd, &src_addr);
> 
>               if (ret == 0)
>                       break;
> @@ -278,8 +277,6 @@ int main(int argc, char **argv)
>                       fprintf(stderr, "failed to receive from netlink\n");
>                       exit(1);
>               } else {
> -                     nlhdr = (struct nlmsghdr *)buf;
> -
>                       switch (nlhdr->nlmsg_type) {
>                       case NLMSG_ERROR:
>                               fprintf(stderr, "err message recieved.\n");
> @@ -304,6 +301,7 @@ int main(int argc, char **argv)
>       }
> 
>       close(sd);
> +     free(nlhdr);
> 
>       while (fsync(STDOUT_FILENO) == -1) {
>               if (errno != EIO)
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Ltp-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ltp-list


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to