[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [dpkg] 05/23: s-s-d: Fix short-lived memory leaks



On 2015-09-14 05:45 +0200, Guillem Jover wrote:

> commit 3db7a6eb4fd16b4cea475009bd80be3a41ada014
> Author: Guillem Jover <guillem@debian.org>
> Date:   Thu May 1 16:34:24 2014 +0200
>
>     s-s-d: Fix short-lived memory leaks
>     
>     As a side effect now a missing group after ‘:’ on --chuid is a fatal
>     error.

There is another rather undesired side effect, which I noticed after this
mail from the daily cron job:

,----
| /etc/cron.daily/man-db:
| start-stop-daemon: group '--iosched' not found
| run-parts: /etc/cron.daily/man-db exited with return code 2
`----

> @@ -1033,9 +1047,12 @@ parse_options(int argc, char * const *argv)
>  		case 'c':  /* --chuid <username>|<uid> */
>  			/* We copy the string just in case we need the
>  			 * argument later. */
> -			changeuser = xstrdup(optarg);
> -			changeuser = strtok(changeuser, ":");
> -			changegroup = strtok(NULL, ":");
> +			changeuser_len = strcspn(optarg, ":");
> +			changeuser = xstrndup(optarg, changeuser_len);
> +			if (optarg[changeuser_len] == ':' &&
> +			    optarg[changeuser_len + 1] == '\0')
> +				fatal("missing group name");
> +			changegroup = xstrdup(optarg + changeuser_len + 1);
>  			break;

Now changegroup will be set even if there is no colon given in the
commandline option.  Attached patch apparently fixes this.

Cheers,
       Sven

>From 642df026cf8e6ca195d09f8084cf53e63f9f2176 Mon Sep 17 00:00:00 2001
From: Sven Joachim <svenjoac@gmx.de>
Date: Thu, 17 Sep 2015 17:31:29 +0200
Subject: [PATCH] s-s-d: Do not set changegroup unconditionally

Commit 3db7a6eb4fd16b4cea475009bd80be3a41ada014 would always set
changegroup in the --chuid option, even if no colon is given on the
commandline.
---
 utils/start-stop-daemon.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 0f4c326..c06ee7d 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -1038,10 +1038,12 @@ parse_options(int argc, char * const *argv)
 			 * argument later. */
 			changeuser_len = strcspn(optarg, ":");
 			changeuser = xstrndup(optarg, changeuser_len);
-			if (optarg[changeuser_len] == ':' &&
-			    optarg[changeuser_len + 1] == '\0')
-				fatal("missing group name");
-			changegroup = optarg + changeuser_len + 1;
+			if (optarg[changeuser_len] == ':') {
+				if (optarg[changeuser_len + 1] == '\0')
+					fatal("missing group name");
+				else
+					changegroup = optarg + changeuser_len + 1;
+			}
 			break;
 		case 'g':  /* --group <group>|<gid> */
 			changegroup = optarg;
-- 
2.5.1


Reply to: