shithub: riscv

Download patch

ref: 9b848903e64bc5af8b7d9671f299ba5b8d9ffbf9
parent: 04c7d5d8f6bde4daa4c582b0053924115b33aca6
author: cinap_lenrek <[email protected]>
date: Wed Mar 22 20:36:57 EDT 2017

upas/smtp: generate 128-bit random message id (was 32 bit), use dBprint(), cleanup unused variables

--- a/sys/src/cmd/upas/smtp/smtp.c
+++ b/sys/src/cmd/upas/smtp/smtp.c
@@ -136,6 +136,7 @@
 	mailfmtinstall();		/* 2047 encoding */
 	fmtinstall('D', Dfmt);
 	fmtinstall('[', encodefmt);
+	fmtinstall('H', encodefmt);
 	errs = malloc(argc*sizeof(char*));
 	reply = s_new();
 	host = 0;
@@ -496,7 +497,6 @@
 	static char buf[1024];
 	char *s, *se, *err;
 	UserPasswd *p;
-	int n;
 	DS ds;
 
 	dialstringparse(farend, &ds);
@@ -677,8 +677,6 @@
 	return 0;
 }
 
-static char hex[] = "0123456789abcdef";
-
 /*
  *  send the damn thing
  */
@@ -685,8 +683,8 @@
 char *
 data(String *from, Biobuf *b, Mx *mx)
 {
-	char *buf, *cp, errmsg[ERRMAX], id[40];
-	int i, n, nbytes, bufsize, eof, r;
+	char *buf, *cp, errmsg[ERRMAX];
+	int n, nbytes, bufsize, eof;
 	String *fromline;
 
 	/*
@@ -751,36 +749,24 @@
 	fromline = convertheader(from);
 	uneaten = buf;
 
-	srand(truerand());
 	if(messageid == 0){
-		for(i = 0; i < 16; i++){
-			r = rand() & 0xff;
-			id[2*i] = hex[r & 0xf];
-			id[2*i + 1] = hex[(r>>4) & 0xf];
-		}
-		id[2*i] = '\0';
-		nbytes += Bprint(&bout, "Message-ID: <%s@%s>\r\n", id, hostdomain);
-		if(debug)
-			Bprint(&berr, "Message-ID: <%s@%s>\r\n", id, hostdomain);
-	}
+		uchar id[16];
 
-	if(originator == 0){
-		nbytes += Bprint(&bout, "From: %s\r\n", s_to_c(fromline));
-		if(debug)
-			Bprint(&berr, "From: %s\r\n", s_to_c(fromline));
+		genrandom(id, sizeof(id));
+		nbytes += dBprint("Message-ID: <%.*H@%s>\r\n",
+			sizeof(id), id, hostdomain);
 	}
+
+	if(originator == 0)
+		nbytes += dBprint("From: %s\r\n", s_to_c(fromline));
 	s_free(fromline);
 
-	if(destination == 0 && toline)
-		if(*s_to_c(toline) == '@'){	/* route addr */
-			nbytes += Bprint(&bout, "To: <%s>\r\n", s_to_c(toline));
-			if(debug)
-				Bprint(&berr, "To: <%s>\r\n", s_to_c(toline));
-		} else {
-			nbytes += Bprint(&bout, "To: %s\r\n", s_to_c(toline));
-			if(debug)
-				Bprint(&berr, "To: %s\r\n", s_to_c(toline));
-		}
+	if(destination == 0 && toline){
+		if(*s_to_c(toline) == '@')	/* route addr */
+			nbytes += dBprint("To: <%s>\r\n", s_to_c(toline));
+		else
+			nbytes += dBprint("To: %s\r\n", s_to_c(toline));
+	}
 
 	if(date == 0 && udate)
 		nbytes += printdate(udate);