Path: utzoo!attcan!uunet!cs.utexas.edu!romp!auschs!awdprime!sandino.austin.ibm.com!jeffe From: jeffe@sandino.austin.ibm.com (Peter Jeffe 512.823.4091) Newsgroups: comp.mail.sendmail Subject: Re: sendmail-5.65 incorrectly handles MX records with equal precedence Keywords: domain.c getmxrr() MX-preference rand() Message-ID: <3924@awdprime.UUCP> Date: 18 Oct 90 14:39:35 GMT References: <26169.271b8651@kuhub.cc.ukans.edu> <1990Oct17.135603.27002@rodan.acs.syr.edu> Sender: news@awdprime.UUCP Organization: IBM AWD, Austin, TX Lines: 25 In article <1990Oct17.135603.27002@rodan.acs.syr.edu> edelsohn@nova.npac.syr.edu (David Edelsohn) writes: >In domain.c: getmxrr(), the MX records are sorted by preference with a >special case if the preferences are identical. The condition is as follows: > > if (prefer[i] > prefer[j] || > (prefer[i] == prefer[j] && rand() % 1 == 0)) { > ...SWAP ENTRIES... > } > >Should not the test be (rand() & 01) or (rand() % 2)? Yes, and as you also point out it should be seeded first with srand[om](). But there is an additional problem with the algorithm: it only randomizes successive *pairs* of records with the same preference. If there are more than two records with the same preference, the first record after the sort will always be one of the first two, etc. The only way I can see around this "some hosts are more equal than others" scenario is to have an additional sort key that is set to a random number, but I'm not sure it's worth the trouble. Any other ideas/comments? ------------------------------------------------------------------------------- Peter Jeffe ...uunet!cs.utexas.edu!ibmchs!auschs!sandino.austin.ibm.com!jeffe first they want a disclaimer, then they make you pee in a jar, then they come for you in the night