Package: src:gap
Version: 4r10p0-6
Severity: wishlist
Tags: sid buster patch

Hi Bill,

a version of the remaining patch that sagemath applies to gap was merged 
upstream a while ago [1] (and tagged for backporting to gap 4.10). embray 
indicated in [2] that the patch is important for non-interactive use of gap so 
I wanted to ask if you would add it to the Debian package now that it is merged.

Best,
Tobias

[1] https://github.com/gap-system/gap/pull/3102

[2] 
https://alioth-lists.debian.net/pipermail/debian-science-sagemath/2019-January/001453.html

From 48b871be128d475898887fc16f8d9958ccbc6e59 Mon Sep 17 00:00:00 2001
From: "Erik M. Bray" <erik.b...@lri.fr>
Date: Tue, 4 Dec 2018 12:44:23 +0000
Subject: [PATCH] prevent infinite recursions in echoandcheck SyWriteandcheck
 in cases where the default stdio output streams cannot be written to

---
 src/sysfiles.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/sysfiles.c b/src/sysfiles.c
index bae7cdc36f..963ed95a36 100644
--- a/src/sysfiles.c
+++ b/src/sysfiles.c
@@ -152,19 +152,24 @@ ssize_t echoandcheck(int fid, const char *buf, size_t count) {
   int ret;
   if (syBuf[fid].type == gzip_socket) {
       ret = gzwrite(syBuf[fid].gzfp, buf, count);
-      if (ret < 0)
+      if (ret < 0) {
           ErrorQuit(
               "Could not write to compressed file, see 'LastSystemError();'\n",
               0L, 0L);
+      }
   }
   else {
       ret = write(syBuf[fid].echo, buf, count);
-      if (ret < 0)
-          ErrorQuit("Could not write to file descriptor %d, see "
-                    "'LastSystemError();'\n",
-                    syBuf[fid].fp, 0L);
+      if (ret < 0) {
+          if (syBuf[fid].fp == fileno(stdout) || syBuf[fid].fp == fileno(stderr)) {
+              Panic("Could not write to stdout/stderr.");
+          } else {
+              ErrorQuit("Could not write to file descriptor %d, see "
+                        "'LastSystemError();'\n",
+                        syBuf[fid].fp, 0L);
+          }
+      }
   }
-
   return ret;
 }
 
@@ -1539,17 +1544,23 @@ static ssize_t SyWriteandcheck(Int fid, const void * buf, size_t count)
     int ret;
     if (syBuf[fid].type == gzip_socket) {
         ret = gzwrite(syBuf[fid].gzfp, buf, count);
-        if (ret < 0)
+        if (ret < 0) {
             ErrorQuit(
                 "Cannot write to compressed file, see 'LastSystemError();'\n",
                 0L, 0L);
+        }
     }
     else {
         ret = write(syBuf[fid].fp, buf, count);
-        if (ret < 0)
-            ErrorQuit("Cannot write to file descriptor %d, see "
-                      "'LastSystemError();'\n",
-                      syBuf[fid].fp, 0L);
+        if (ret < 0) {
+            if (syBuf[fid].fp == fileno(stdout) || syBuf[fid].fp == fileno(stderr)) {
+                Panic("Could not write to stdout/stderr.");
+            } else {
+                ErrorQuit("Cannot write to file descriptor %d, see "
+                          "'LastSystemError();'\n",
+                          syBuf[fid].fp, 0L);
+            }
+        }
     }
 
     return ret;

Reply via email to