[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [patch] bb_perror_nomsg_and_die() seg fault
From:       Denis Vlasenko <vda.linux () googlemail ! com>
Date:       2007-05-29 21:42:14
Message-ID: 200705292342.14996.vda.linux () googlemail ! com
[Download RAW message or body]

On Tuesday 29 May 2007 12:05, Daniel Farrugia wrote:
> The following trivial patch fixed this problem for me:
> 
> diff -urN a/libbb/perror_nomsg_and_die.c b/libbb/perror_nomsg_and_die.c
> --- a/libbb/perror_nomsg_and_die.c  2007-05-20 18:56:18.000000000 +0200
> +++ b/libbb/perror_nomsg_and_die.c  2007-05-29 11:11:54.000000000 +0200
> @@ -17,5 +17,5 @@
>  void bb_perror_nomsg_and_die(void);
>  void bb_perror_nomsg_and_die(void)
>  {
> -       bb_perror_msg_and_die(0);
> +       bb_perror_msg_and_die("");
>  }

This fix is in the wrong place. It's better to stem the problem
in bb_verror_msg().

Please try attached patch.
--
vda

["4.patch" (text/x-diff)]

diff -d -urpN busybox.3/libbb/verror_msg.c busybox.4/libbb/verror_msg.c
--- busybox.3/libbb/verror_msg.c	2007-05-23 02:35:33.000000000 +0200
+++ busybox.4/libbb/verror_msg.c	2007-05-29 23:33:06.000000000 +0200
@@ -20,6 +20,9 @@ void bb_verror_msg(const char *s, va_lis
 	va_list p2;
 	va_copy(p2, p);
 
+	if (!s) /* nomsg[_and_die] uses NULL fmt */
+		s = ""; /* some libc don't like printf(NULL) */
+
 	if (logmode & LOGMODE_STDIO) {
 		fflush(stdout);
 		fprintf(stderr, "%s: ", applet_name);
@@ -28,7 +31,7 @@ void bb_verror_msg(const char *s, va_lis
 			fputs(msg_eol, stderr);
 		else
 			fprintf(stderr, "%s%s%s",
-					s ? ": " : "",
+					s[0] ? ": " : "",
 					strerr, msg_eol);
 	}
 	if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) {
@@ -36,8 +39,10 @@ void bb_verror_msg(const char *s, va_lis
 			vsyslog(LOG_ERR, s, p2);
 		else  {
 			char *msg;
-			if (vasprintf(&msg, s, p2) < 0)
-				bb_error_msg_and_die(bb_msg_memory_exhausted);
+			if (vasprintf(&msg, s, p2) < 0) {
+				fprintf(stderr, "%s: %s\n", applet_name, bb_msg_memory_exhausted);
+				xfunc_die();
+			}
 			syslog(LOG_ERR, "%s: %s", msg, strerr);
 			free(msg);
 		}


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic