cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Yet another minor patch

From: Yang Tse <yangsita_at_gmail.com>
Date: Fri, 25 Nov 2005 20:27:58 +0100

And here goes a couple more ...

First one gets rid of some compiler warnings.

diff -urp c:\f\curl-old/curl/ares/ares_process.c
c:\f\curl-new/curl/ares/ares_process.c
--- c:\f\curl-old/curl/ares/ares_process.c 2005-08-10 19:08:30.000000000 +0200
+++ c:\f\curl-new/curl/ares/ares_process.c 2005-11-25 16:46:05.675931200 +0100
@@ -164,7 +164,8 @@ static void write_tcp_data(ares_channel
           /* Can't allocate iovecs; just send the first request. */
           sendreq = server->qhead;

- scount = send(server->tcp_socket, sendreq->data, sendreq->len, 0);
+ scount = send(server->tcp_socket, (void *)sendreq->data,
+ sendreq->len, 0);

           if (scount < 0)
             {
@@ -212,7 +213,7 @@ static void read_tcp_data(ares_channel c
            * what's left to read of it).
            */
           count = recv(server->tcp_socket,
- server->tcp_lenbuf + server->tcp_buffer_pos,
+ (void *)(server->tcp_lenbuf + server->tcp_buffer_pos),
                        2 - server->tcp_buffer_pos, 0);
           if (count <= 0)
             {
@@ -238,7 +239,7 @@ static void read_tcp_data(ares_channel c
         {
           /* Read data into the allocated buffer. */
           count = recv(server->tcp_socket,
- server->tcp_buffer + server->tcp_buffer_pos,
+ (void *)(server->tcp_buffer + server->tcp_buffer_pos),
                        server->tcp_length - server->tcp_buffer_pos, 0);
           if (count <= 0)
             {
@@ -280,7 +281,7 @@ static void read_udp_packets(ares_channe
           !FD_ISSET(server->udp_socket, read_fds))
         continue;

- count = recv(server->udp_socket, buf, sizeof(buf), 0);
+ count = recv(server->udp_socket, (void *)buf, sizeof(buf), 0);
       if (count <= 0)
         handle_error(channel, i, now);

@@ -465,7 +466,8 @@ void ares__send_query(ares_channel chann
               return;
             }
         }
- if (send(server->udp_socket, query->qbuf, query->qlen, 0) == -1)
+ if (send(server->udp_socket, (void *)query->qbuf,
+ query->qlen, 0) == -1)
         {
           query->skip_server[query->server] = 1;
           next_server(channel, query, now);

Second one fixes a compiler warning and minimizes the risk of a buffer overflow.

diff -urp c:\f\curl-old/curl/ares/ares_getnameinfo.c
c:\f\curl-new/curl/ares/ares_getnameinfo.c
--- c:\f\curl-old/curl/ares/ares_getnameinfo.c 2005-11-25
00:03:25.000000000 +0100
+++ c:\f\curl-new/curl/ares/ares_getnameinfo.c 2005-11-25
20:05:53.994286400 +0100
@@ -324,25 +324,30 @@ static char *lookup_service(unsigned sho
 static char *append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
                             char *buf)
 {
- char tmpbuf[IF_NAMESIZE + 1];
+ char *fmt = NULL;
+ char fmt_u[] = "%u";
+ char fmt_lu[] = "%lu";
+ char tmpbuf[IF_NAMESIZE + 2];

   tmpbuf[0] = '%';
+ fmt = (sizeof(addr6->sin6_scope_id) > sizeof(unsigned int))?fmt_lu:fmt_u;
 #ifdef HAVE_IF_INDEXTONAME
   if ((flags & ARES_NI_NUMERICSCOPE) ||
       (!IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)
        && !IN6_IS_ADDR_MC_LINKLOCAL(&addr6->sin6_addr)))
     {
- sprintf(&tmpbuf[1], "%u", addr6->sin6_scope_id);
+ sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
     }
   else
     {
       if (if_indextoname(addr6->sin6_scope_id, &tmpbuf[1]) == NULL)
- sprintf(&tmpbuf[1], "%u", addr6->sin6_scope_id);
+ sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
     }
 #else
- sprintf(&tmpbuf[1], "%u", addr6->sin6_scope_id);
+ sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
   (void) flags;
 #endif
+ tmpbuf[IF_NAMESIZE + 1] = '\0';
   strcat(buf, tmpbuf);
   return buf;
 }

Regards,
Yang
Received on 2005-11-25