public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: libc-hacker@sourceware.org
Subject: Unaligned addresses in resolver
Date: Thu, 18 Sep 2008 08:40:00 -0000	[thread overview]
Message-ID: <je4p4dkftl.fsf@sykes.suse.de> (raw)

__libc_res_nsend can generate an unaligned address for the answer
header.

Andreas.

2008-09-18  Andreas Schwab  <schwab@suse.de>

	* resolv/res_send.c (send_vc): Fix use of unaligned address.
        Properly handle partial reads.

--- resolv/res_send.c	29 Jul 2008 10:01:10 +0200	1.58
+++ resolv/res_send.c	17 Sep 2008 18:07:56 +0200	
@@ -734,11 +734,11 @@ send_vc(res_state statp,
 	 */
 	int recvresp1 = 0;
 	int recvresp2 = buf2 == NULL;
- read_len:
-	cp = ans;
 	uint16_t rlen16;
+ read_len:
+	cp = (u_char *)&rlen16;
 	len = sizeof(rlen16);
-	while ((n = TEMP_FAILURE_RETRY (read(statp->_vcsock, &rlen16,
+	while ((n = TEMP_FAILURE_RETRY (read(statp->_vcsock, cp,
 					     (int)len))) > 0) {
 		cp += n;
 		if ((len -= n) <= 0)
@@ -778,8 +778,16 @@ send_vc(res_state statp,
 			/* No buffer allocated for the first
 			   reply.  We can try to use the rest
 			   of the user-provided buffer.  */
+#ifdef _STRING_ARCH_unaligned
 			*anssizp2 = orig_anssizp - resplen;
 			*ansp2 = *ansp + resplen;
+#else
+			int aligned_resplen
+			  = ((resplen + __alignof__ (HEADER) - 1)
+			     & (__alignof__ (HEADER) - 1));
+			*anssizp2 = orig_anssizp - aligned_resplen;
+			*ansp2 = *ansp + aligned_resplen;
+#endif
 		} else {
 			/* The first reply did not fit into the
 			   user-provided buffer.  Maybe the second

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

                 reply	other threads:[~2008-09-18  8:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=je4p4dkftl.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=libc-hacker@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).