You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
2.3 KiB

From 2b1643d361274d52259820561747165af423a420 Mon Sep 17 00:00:00 2001
From: Mamoru TASAKA <mtasaka@fedoraproject.org>
Date: Mon, 28 Dec 2020 15:14:30 +0900
Subject: [PATCH 4/6] xscreensaver-systemd: fix blurb strncpy
Shut up the following gcc11 -Wall warning:
---------------------------------------------
In function 'strncpy',
inlined from 'blurb' at ../../driver/xscreensaver-systemd.c:387:3:
/usr/include/bits/string_fortified.h:91:10: warning: 'strncpy' output may be truncated copying 8 bytes from a string of length 88 [-Wstringop-truncation]
---------------------------------------------
Note that the current blurb() implementation contains some code which is
actually not working. Currently:
---------------------------------------------
376 blurb (void)
377 {
378 static char buf[255];
386 ctime_r (&now, ct);
387 strncpy(buf+n, ct+11, 8);
388 strcpy(buf+n+9, ": ");
389 return buf;
390 }
---------------------------------------------
With the line 378, the contents of buf[] is all initialized to 0.
the line 388 strncpy() puts some string from ct to
buf[n+0], buf[n+1], ... , and buf[n+7] (8 bytes, not putting terminating
null character). Here buf[n+8] is still 0 (null character) because
buf[] is all initialized to 0.
The line 388 puts the string to buf[n+9] and buf[n+10], but as
buf[n+8] is still 0, the line 388 does essentially nothing.
Note that the other part of this file calls blurb() like:
----------------------------------------------
402 fprintf (stderr, "%s: exec: %s\n", blurb(), buf);
----------------------------------------------
i.e. "%s" always followed by ":" which compensates for the line 388.
---
driver/xscreensaver-systemd.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/driver/xscreensaver-systemd.c b/driver/xscreensaver-systemd.c
index 2da99de..f6bd104 100644
--- a/driver/xscreensaver-systemd.c
+++ b/driver/xscreensaver-systemd.c
@@ -378,14 +378,8 @@ blurb (void)
static char buf[255];
time_t now = time ((time_t *) 0);
char ct[100];
- int n = strlen(progname);
- if (n > 100) n = 99;
- strncpy(buf, progname, n);
- buf[n++] = ':';
- buf[n++] = ' ';
ctime_r (&now, ct);
- strncpy(buf+n, ct+11, 8);
- strcpy(buf+n+9, ": ");
+ sprintf(buf, "%.99s: %.8s", progname, ct+11);
return buf;
}
--
2.29.2