Parcourir la source

When I switched from using stack allocated space for printf, I missed a case
where a sizeof(foo) was changed to the sizeof a pointer. This caused
_dl_printf to complain a lot when debug is enabled (which itself revealed a bug
since it should have exited on buffer overflow), and let me to find another
bug, where memory failures would try to recursively call _dl_printf....
What a mess.

Eric Andersen il y a 20 ans
Parent
commit
f3651e4e20
2 fichiers modifiés avec 10 ajouts et 6 suppressions
  1. 5 3
      ldso/ldso/dl-elf.c
  2. 5 3
      ldso/ldso/readelflib1.c

+ 5 - 3
ldso/ldso/dl-elf.c

@@ -787,7 +787,7 @@ void _dl_dprintf(int fd, const char *fmt, ...)
 	buf = _dl_mmap((void *) 0, 4096, PROT_READ | PROT_WRITE,
 		MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 	if (_dl_mmap_check_error(buf)) {
-			_dl_dprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
+			_dl_write(fd, "mmap of a spare page failed!\n", 29); 
 			_dl_exit(20);
 	}
 
@@ -796,8 +796,10 @@ void _dl_dprintf(int fd, const char *fmt, ...)
 	if (!fmt)
 		return;
 
-	if (_dl_strlen(fmt) >= (sizeof(buf) - 1))
-		_dl_write(fd, "(overflow)\n", 10);
+	if (_dl_strlen(fmt) >= (4096 - 1)) {
+		_dl_write(fd, "overflow\n", 11);
+		_dl_exit(20);
+	}
 
 	_dl_strcpy(buf, fmt);
 	va_start(args, fmt);

+ 5 - 3
ldso/ldso/readelflib1.c

@@ -787,7 +787,7 @@ void _dl_dprintf(int fd, const char *fmt, ...)
 	buf = _dl_mmap((void *) 0, 4096, PROT_READ | PROT_WRITE,
 		MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 	if (_dl_mmap_check_error(buf)) {
-			_dl_dprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
+			_dl_write(fd, "mmap of a spare page failed!\n", 29); 
 			_dl_exit(20);
 	}
 
@@ -796,8 +796,10 @@ void _dl_dprintf(int fd, const char *fmt, ...)
 	if (!fmt)
 		return;
 
-	if (_dl_strlen(fmt) >= (sizeof(buf) - 1))
-		_dl_write(fd, "(overflow)\n", 10);
+	if (_dl_strlen(fmt) >= (4096 - 1)) {
+		_dl_write(fd, "overflow\n", 11);
+		_dl_exit(20);
+	}
 
 	_dl_strcpy(buf, fmt);
 	va_start(args, fmt);