File util-linux-script-fclose-crash.patch of Package util-linux.4768

From 4b0b416acb182576ab1000a1df1ad3722a25f071 Mon Sep 17 00:00:00 2001
From: Sami Kerola <kerolasa@iki.fi>
Date: Sat, 16 Apr 2016 17:43:01 +0100
Subject: [PATCH] script: avoid trying fclose(NULL)

Here is a one-liner to reproduce the issue.

$ mkdir example && cd example && chmod 0500 . && script
Script started, file is typescript
script: cannot open typescript: Permission denied
                                                 Script done, file is typescript
Segmentation fault (core dumped)

Addresses: https://bugs.launchpad.net/bugs/1537518
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/script.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 279b9ecfe..d691c2231 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -205,7 +205,8 @@ static void __attribute__((__noreturn__)) done(struct script_control *ctl)
 
 	if (ctl->timingfp)
 		fclose(ctl->timingfp);
-	fclose(ctl->typescriptfp);
+	if (ctl->typescriptfp)
+		fclose(ctl->typescriptfp);
 
 	if (ctl->rc_wanted) {
 		if (WIFSIGNALED(ctl->childstatus))
-- 
2.11.0

openSUSE Build Service is sponsored by