svn commit: trunk/busybox: networking runit

vda at busybox.net vda at busybox.net
Tue Aug 21 11:18:26 UTC 2007


Author: vda
Date: 2007-08-21 04:18:25 -0700 (Tue, 21 Aug 2007)
New Revision: 19611

Log:
httpd: fix buglet in hex conversion. Remove alloca NULL checks
(never happens, app just crashes if stack overflows)
svlogd: cosmetic messages and style fixes



Modified:
   trunk/busybox/networking/httpd.c
   trunk/busybox/runit/svlogd.c


Changeset:
Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2007-08-21 10:58:18 UTC (rev 19610)
+++ trunk/busybox/networking/httpd.c	2007-08-21 11:18:25 UTC (rev 19611)
@@ -163,7 +163,7 @@
 #endif
 };
 
-static const uint16_t http_response_type[] = {
+static const uint16_t http_response_type[] ALIGN2 = {
 	HTTP_OK,
 	HTTP_MOVED_TEMPORARILY,
 	HTTP_REQUEST_TIMEOUT,
@@ -287,8 +287,6 @@
 } while (0)
 
 
-
-
 #define STRNCASECMP(a, str) strncasecmp((a), (str), sizeof(str)-1)
 
 /* Prototypes */
@@ -467,11 +465,6 @@
 
 	if (flag == SUBDIR_PARSE || cf == NULL) {
 		cf = alloca(strlen(path) + sizeof(httpd_conf) + 2);
-		if (cf == NULL) {
-			if (flag == FIRST_PARSE)
-				bb_error_msg_and_die(bb_msg_memory_exhausted);
-			return;
-		}
 		sprintf((char *)cf, "%s/%s", path, httpd_conf);
 	}
 
@@ -554,7 +547,7 @@
 			/* error status code */
 			int status = atoi(++p0);
 			/* c already points at the character following ':' in parse loop */
-			// c = strchr(p0, ':'); c++;
+			/* c = strchr(p0, ':'); c++; */
 			if (status < HTTP_CONTINUE) {
 				bb_error_msg("config error '%s' in '%s'", buf, cf);
 				continue;
@@ -575,9 +568,7 @@
 		if (*p0 == '/') {
 			/* make full path from httpd root / current_path / config_line_path */
 			cf = (flag == SUBDIR_PARSE ? path : "");
-			p0 = malloc(strlen(cf) + (c - buf) + 2 + strlen(c));
-			if (p0 == NULL)
-				continue;
+			p0 = xmalloc(strlen(cf) + (c - buf) + 2 + strlen(c));
 			c[-1] = '\0';
 			sprintf(p0, "/%s%s", cf, buf);
 
@@ -694,9 +685,11 @@
 	char ch;
 
 	while ((ch = *string++)) {
-		// very simple check for what to encode
-		if (isalnum(ch)) *p++ = ch;
-		else p += sprintf(p, "&#%d;", (unsigned char) ch);
+		/* very simple check for what to encode */
+		if (isalnum(ch))
+			*p++ = ch;
+		else
+			p += sprintf(p, "&#%d;", (unsigned char) ch);
 	}
 	*p = '\0';
 	return out;
@@ -717,18 +710,21 @@
  */
 static unsigned hex_to_bin(unsigned char c)
 {
-	unsigned v = c | 0x20; /* lowercase */
-	v = v - '0';
+	unsigned v;
+
+	v = c - '0';
 	if (v <= 9)
 		return v;
-	v = v + ('0' - 'a');
+	/* c | 0x20: letters to lower case, non-letters
+	 * to (potentially different) non-letters */
+	v = (unsigned)(c | 0x20) - 'a';
 	if (v <= 5)
 		return v + 10;
 	return ~0;
 }
 /* For testing:
-void t(char c) { printf("'%c' %u\n", c, hex_to_bin(c)); }
-int main() { t('0'); t('9'); t('A'); t('F'); t('a'); t('f');
+void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); }
+int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f');
 t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; }
 */
 static char *decodeString(char *orig, int option_d)

Modified: trunk/busybox/runit/svlogd.c
===================================================================
--- trunk/busybox/runit/svlogd.c	2007-08-21 10:58:18 UTC (rev 19610)
+++ trunk/busybox/runit/svlogd.c	2007-08-21 11:18:25 UTC (rev 19611)
@@ -513,22 +513,25 @@
 	/* read config */
 	i = open_read_close("config", buf, sizeof(buf));
 	if (i < 0 && errno != ENOENT)
-		bb_perror_msg(WARNING": %s/config", ld->name);
+		bb_perror_msg(WARNING"%s/config", ld->name);
 	if (i > 0) {
 		if (verbose)
 			bb_error_msg(INFO"read: %s/config", ld->name);
 		s = buf;
 		while (s) {
 			np = strchr(s, '\n');
-			if (np) *np++ = '\0';
+			if (np)
+				*np++ = '\0';
 			switch (s[0]) {
 			case '+':
 			case '-':
 			case 'e':
 			case 'E':
+				/* Add '\n'-terminated line to ld->inst */
 				while (1) {
-					int l = asprintf(&new, "%s%s\n", ld->inst?:"", s);
-					if (l >= 0 && new) break;
+					int l = asprintf(&new, "%s%s\n", ld->inst ? : "", s);
+					if (l >= 0 && new)
+						break;
 					pause_nomem();
 				}
 				free(ld->inst);
@@ -578,7 +581,8 @@
 		s = ld->inst;
 		while (s) {
 			np = strchr(s, '\n');
-			if (np) *np++ = '\0';
+			if (np)
+				*np++ = '\0';
 			s = np;
 		}
 	}
@@ -586,7 +590,7 @@
 	/* open current */
 	i = stat("current", &st);
 	if (i != -1) {
-		if (st.st_size && ! (st.st_mode & S_IXUSR)) {
+		if (st.st_size && !(st.st_mode & S_IXUSR)) {
 			ld->fnsave[25] = '.';
 			ld->fnsave[26] = 'u';
 			ld->fnsave[27] = '\0';
@@ -600,8 +604,9 @@
 			rmoldest(ld);
 			i = -1;
 		} else {
-			/* Be paranoid: st.st_size can be not just bigger, but WIDER! */
-			/* (bug in original svlogd. remove this comment when fixed there) */
+			/* st.st_size can be not just bigger, but WIDER!
+			 * This code is safe: if st.st_size > 4GB, we select
+			 * ld->sizemax (because it's "unsigned") */
 			ld->size = (st.st_size > ld->sizemax) ? ld->sizemax : st.st_size;
 		}
 	} else {
@@ -667,7 +672,7 @@
 	int i;
 
 	input.fd = 0;
-        input.events = POLLIN|POLLHUP|POLLERR;
+	input.events = POLLIN;
 
 	do {
 		if (rotateasap) {
@@ -744,7 +749,6 @@
 	return i;
 }
 
-
 static void sig_term_handler(int sig_no)
 {
 	if (verbose)




More information about the busybox-cvs mailing list