To be specific

- looking at the code (my current fork but on sed is almost aligned
apart from an inline function), it does process both. The issue is
ORDERING, not ignoring

Therefore, to confirm the bug the best way is

- 1. to have a reproducible test case in the busybox test suite
- 2. determine which version was used that shows an issue
- 3. about #2, consider that the build uses an older bb version

In attachment a patch that unfortunately causes regressions which are
not acceptable IMHO.

Best regards,
--
Roberto A. Foglietta
+49.176.274.75.661
+39.349.33.30.697

On Fri, 7 Aug 2026 at 04:30, G. Branden Robinson via busybox
<[email protected]> wrote:
>
> [looping in busybox mailing list; Bruno found a sed portability problem]
>
> Background:
> https://savannah.gnu.org/bugs/?68601
>
> Hi Bruno,
>
> At 2026-08-06T18:07:55+0200, Bruno Haible wrote:
> > I wrote:
> > > The reason is that the 'sed' program on this platform (from BusyBox)
> > > ignores '-e' options when a '-f' option is present, regardless
> > > whether the '-e' options come before or after the '-f' option.
> >
> > Addendum: This is not the case in general, but is the case with this
> > particular '-f' script and these particular '-e' options.
>
> I didn't experiment to determine the issue, but the following change in
> wording from POSIX Issue 4 to Issue 8 might account for the discrepancy.
>
> Issue 4:
>
> −f script_file          Add the editing commands in the file script_file
>                         to the end of the script.
>
> Issue 8:
>
> −f script_file          Add the editing commands in the file script_file
>                         to the end of the script of editing commands.
>
> I wonder what alternative script the Busybox developers have in mind.
>
> Regards,
> Branden
> _______________________________________________
> busybox mailing list
> [email protected]
> https://lists.busybox.net/mailman/listinfo/busybox
From 1b6b8572f3f3ed77cdb6496784c35bbd775b17eb Mon Sep 17 00:00:00 2001
From: "Roberto A. Foglietta" <[email protected]>
Date: Mon, 17 Aug 2026 07:38:13 +0200
Subject: [PATCH] sed.c: POSIX compliance fix about '-f' with '-e' ordered
 options

bug found:

- https://savannah.gnu.org/bugs/?68601

fix size:

   text    data     bss     dec     hex filename
   7352       0       0    7352    1cb8 editors/sed.o
   7441       0       0    7441    1d11 editors/sed.o v1
   7465       0       0    7465    1d29 editors/sed.o v2
                           +113

regression:

- what about -nre? or -nve? uncommon but lecit and broken

Signed-off-by: Roberto A. Foglietta <[email protected]>
---
 editors/sed.c | 47 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/editors/sed.c b/editors/sed.c
index 029e9b8e7..9d14294fb 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1528,7 +1528,7 @@ static void add_cmd_block(char *cmdstr)
 int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int sed_main(int argc UNUSED_PARAM, char **argv)
 {
-	unsigned opt;
+	unsigned opt, i;
 	llist_t *opt_e, *opt_f;
 	char *opt_i;
 
@@ -1568,6 +1568,37 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
 			sed_longopts,
 			&opt_i, &opt_e, &opt_f,
 			&G.be_quiet); /* counter for -n */
+
+
+	/* Process -e and -f options in command line order.
+	 * getopt32long stores them in separate lists, losing
+	 * their relative order. We re-scan argv to preserve it.
+	 */
+	for (i = 1; i < optind; i++)
+	{
+		char *p = argv[i], c = *p;
+		if (c != '-' || !*++p) //'-'
+			continue;
+		if (*p == '-' && !*++p) //'--'
+			continue;
+		c = *p;
+		if (c == 'e' && opt_e) {
+			add_cmd_block(llist_pop(&opt_e));
+		}
+		else
+		if (c == 'f' && opt_f) {
+			char *line;
+			FILE *cmdfile = xfopen_stdin(llist_pop(&opt_f));
+			while ( (line = xmalloc_fgetline(cmdfile)) ) {
+				add_cmd(line);
+				free(line);
+			}
+			fclose_if_not_stdin(cmdfile);
+		}
+	}
+	llist_free(opt_e, free);
+	llist_free(opt_f, free);
+
 	//argc -= optind;
 	argv += optind;
 	if (opt & OPT_in_place) { // -i
@@ -1577,19 +1608,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
 		G.regex_type |= REG_EXTENDED; // -r or -E
 	//if (opt & 8)
 	//	G.be_quiet++; // -n (implemented with a counter instead)
-	while (opt_e) { // -e
-		add_cmd_block(llist_pop(&opt_e));
-	}
-	while (opt_f) { // -f
-		char *line;
-		FILE *cmdfile;
-		cmdfile = xfopen_stdin(llist_pop(&opt_f));
-		while ((line = xmalloc_fgetline(cmdfile)) != NULL) {
-			add_cmd(line);
-			free(line);
-		}
-		fclose_if_not_stdin(cmdfile);
-	}
+
 	/* if we didn't get a pattern from -e or -f, use argv[0] */
 	if (!(opt & 0x30)) {
 		if (!*argv)
-- 
2.34.1

  • ... G. Branden Robinson
    • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
      • ... G. Branden Robinson
      • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
        • ... G. Branden Robinson
          • ... Roberto A. Foglietta
            • ... G. Branden Robinson
          • ... Roberto A. Foglietta
            • ... Roberto A. Foglietta
    • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
    • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
    • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
    • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
    • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
      • ... G. Branden Robinson
        • ... Bruno Haible via discussion of the GNU roff typesetting system and related software
          • ... G. Branden Robinson
            • ... Bruno Haible via discussion of the GNU roff typesetting system and related software

Reply via email to