shell: add preceding newline to delimiter

at uses heredoc redirection to pass the script being executed
into user's defined $SHELL. However, the heredoc delimiter
is directly concatenated to the script's contents;
if these contents do not end with a newline,
the delimiter is attached to the last line of the script.

This patch adds a single newline to be always emmited before the
delimiter. This guarantees the delimiter is always on it's own
line. In case a newline is already present at the end of the original
script, this simply adds a single empty line; I cannot think of any
complication that could result from that.

Resolves: rhbz#2070450
This commit is contained in:
Jan Staněk 2022-03-31 12:13:56 +02:00
parent 41850fcf84
commit d72ffaead4
No known key found for this signature in database
GPG Key ID: 2972F2037B243B6D
2 changed files with 10 additions and 7 deletions

View File

@ -4,13 +4,13 @@ diff -ur b/at.c a/at.c
@@ -62,11 +62,8 @@
#include <stdlib.h>
#include <string.h>
-#ifdef TM_IN_SYS_TIME
#include <sys/time.h>
-#else
#include <time.h>
-#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -245,6 +242,12 @@
@ -23,13 +23,13 @@ diff -ur b/at.c a/at.c
+
+ gettimeofday(&tv, &tz);
+ srandom(getpid()+tv.tv_usec);
/* Install the signal handler for SIGINT; terminate after removing the
* spool file if necessary
@@ -492,6 +495,9 @@
fprintf(fp, " || {\n\t echo 'Execution directory "
"inaccessible' >&2\n\t exit 1\n}\n");
+ i = random();
+ fprintf(fp, "${SHELL:-/bin/sh} << \'marcinDELIMITER%08lx\'\n", i);
+
@ -41,7 +41,7 @@ diff -ur b/at.c a/at.c
fprintf(stderr, "<EOT>\n");
}
- fprintf(fp, "\n");
+ fprintf(fp, "marcinDELIMITER%08lx\n", i);
+ fprintf(fp, "\nmarcinDELIMITER%08lx\n", i);
if (ferror(fp))
panic("Output error");
fflush(fp);

View File

@ -3,7 +3,7 @@
Summary: Job spooling tools
Name: at
Version: 3.2.5
Release: 2%{?dist}
Release: 3%{?dist}
# http://packages.debian.org/changelogs/pool/main/a/at/current/copyright
# + install-sh is MIT license with changes under Public Domain
License: GPLv3+ and GPLv2+ and ISC and MIT and Public Domain
@ -164,9 +164,12 @@ chown root:root %{_localstatedir}/spool/at/.SEQ
%attr(0644,root,root) /%{_unitdir}/atd.service
%changelog
* Thu Mar 31 2022 Jan Staněk <jstanek@redhat.com> - 3.2.5-3
- Add preceding newline to delimiter in at-3.2.2-shell.patch
* Tue Mar 08 2022 Ondřej Pohořelský <opohorel@redhat.com> - 3.2.5-2
- Add mising directory and batch-job script into at-3.2.5-make.patch
- Defined datadir in %%install section and listed batch-job in %%files section
- Defined datadir in %%install section and listed batch-job in %%files section
* Tue Mar 01 2022 Ondřej Pohořelský <opohorel@redhat.com> - 3.2.5-1
- Update to new upstream release