ppp/ppp-fork-fix.patch
Reinhard Max 4505baafb8 - New version 2.4.8.
* New pppd options have been added:
    * ifname, to set the name for the PPP interface device
    * defaultroute-metric, to set the metric for the default route
    * defaultroute6, to add an IPv6 default route (with
      nodefaultroute6 to prevent adding an IPv6 default route).
    * up_sdnotify, to have pppd notify systemd when the link is up.
  * The rp-pppoe plugin has new options:
    * host-uniq, to set the Host-Uniq value to send
    * pppoe-padi-timeout, to set the timeout for discovery packets
    * pppoe-padi-attempts, to set the number of discovery attempts.
  * Added the CLASS attribute in radius packets.
  * Fixed warnings and issues found by static analysis.
- Obsoleted patches:
  [...]
- Patches that got renamed, because they needed rediffing:
 [...] 
- bsc#1172916: Fix an outdated comment for lcp-echo-interval.

OBS-URL: https://build.opensuse.org/package/show/network/ppp?expand=0&rev=60
2020-08-03 15:45:36 +00:00

92 lines
2.2 KiB
Diff

--- pppd/main.c.orig
+++ pppd/main.c
@@ -1551,14 +1551,6 @@ safe_fork(int infd, int outfd, int errfd
int fd, pipefd[2];
char buf[1];
- /* make sure fds 0, 1, 2 are occupied (probably not necessary) */
- while ((fd = dup(fd_devnull)) >= 0) {
- if (fd > 2) {
- close(fd);
- break;
- }
- }
-
if (pipe(pipefd) == -1)
pipefd[0] = pipefd[1] = -1;
pid = fork();
@@ -1582,25 +1574,31 @@ safe_fork(int infd, int outfd, int errfd
tdb_close(pppdb);
#endif
- /* make sure infd, outfd and errfd won't get tromped on below */
- if (infd == 1 || infd == 2)
- infd = dup(infd);
- if (outfd == 0 || outfd == 2)
- outfd = dup(outfd);
- if (errfd == 0 || errfd == 1)
- errfd = dup(errfd);
-
+ /* make sure fds 0, 1, 2 are occupied, so the duplicated fds always > 2 */
+ while ((fd = dup(fd_devnull)) >= 0) {
+ if (fd > 2) {
+ close(fd);
+ break;
+ }
+ }
+
+ /* always copy fd's to avoid to use a already closed fd later */
+ {
+ int fdi = infd, fdo = outfd;
+
+ infd = dup(infd);
+ outfd = dup(outfd);
+ if (errfd >= 0) {
+ fd = errfd;
+ errfd = dup(errfd);
+ close(fd);
+ }
+ close(fdi);
+ close(fdo);
+ }
closelog();
- /* dup the in, out, err fds to 0, 1, 2 */
- if (infd != 0)
- dup2(infd, 0);
- if (outfd != 1)
- dup2(outfd, 1);
- if (errfd != 2)
- dup2(errfd, 2);
-
- if (log_to_fd > 2)
+ if (log_to_fd > 0)
close(log_to_fd);
if (the_channel->close)
(*the_channel->close)();
@@ -1608,12 +1606,18 @@ safe_fork(int infd, int outfd, int errfd
close(devfd); /* some plugins don't have a close function */
close(fd_ppp);
close(fd_devnull);
- if (infd != 0)
- close(infd);
- if (outfd != 1)
- close(outfd);
- if (errfd != 2)
- close(errfd);
+
+ close(0);
+ dup2(infd, 0);
+ close(infd);
+ close(1);
+ dup2(outfd, 1);
+ close(outfd);
+ if (errfd >= 0) {
+ close(2);
+ dup2(errfd, 2);
+ close(errfd);
+ }
notify(fork_notifier, 0);
close(pipefd[0]);