101c9a4968
- fixes build issus on 64-bit ppc and s390 - Added a patch to bring sysfsutils up to latest upstream, which now is in place: * sysfsutils-latest-changes.diff.gz - Added patches which have been submitted upstream but not yet merged: * 0001-Fix-compiler-complain-about-multiple-defs-of-my_stdo.patch * 0002-Fix-compiler-complaint-about-string-truncation.patch * 0003-Fix-more-string-issues-for-gcc-10.patch And removing a patch that's subsumed by the above patches: * sysfsutils-fix-compiler-issues.patch Lastly, replaced the hand-rolled sysfsutils-2.1.0.tar.gz with upstream archive file sysfsutils-sysfsutils-2_1_0.tar.gz, though the contents of the two are the same. OBS-URL: https://build.opensuse.org/request/show/817114 OBS-URL: https://build.opensuse.org/package/show/Base:System/sysfsutils?expand=0&rev=18
99 lines
2.9 KiB
Diff
99 lines
2.9 KiB
Diff
From 0719881cad85f837f039ecb378b823306640902a Mon Sep 17 00:00:00 2001
|
|
From: Lee Duncan <lduncan@suse.com>
|
|
Date: Thu, 25 Jun 2020 08:05:18 -0700
|
|
Subject: [PATCH 3/6] Fix more string issues for gcc-10
|
|
|
|
These issues only surfaced for 64-bit PPC and for s390, having
|
|
to do with the home-grown strncat() the code was using, which
|
|
was just a macro.
|
|
---
|
|
cmd/systool.c | 3 ++-
|
|
lib/sysfs.h | 3 ++-
|
|
lib/sysfs_utils.c | 29 +++++++++++++++++++----------
|
|
3 files changed, 23 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/cmd/systool.c b/cmd/systool.c
|
|
index 45ed36db1d54..f4060f57a6ca 100644
|
|
--- a/cmd/systool.c
|
|
+++ b/cmd/systool.c
|
|
@@ -36,7 +36,8 @@ extern char *my_strncpy(char *to, const char *from, size_t max);
|
|
#define safestrcpy(to, from) my_strncpy(to, from, sizeof(to))
|
|
#define safestrcpymax(to, from, max) my_strncpy(to, from, max)
|
|
|
|
-#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
|
|
+extern char *my_strncat(char *to, const char *from, size_t max);
|
|
+#define safestrcat(to, from) my_strncat(to, from, sizeof(to) - strlen(to) - 1)
|
|
|
|
#define safestrcatmax(to, from, max) \
|
|
do { \
|
|
diff --git a/lib/sysfs.h b/lib/sysfs.h
|
|
index 481c1e9b7cf2..a9c14317ec4c 100644
|
|
--- a/lib/sysfs.h
|
|
+++ b/lib/sysfs.h
|
|
@@ -37,7 +37,8 @@ extern char *my_strncpy(char *to, const char *from, size_t max);
|
|
#define safestrcpy(to, from) my_strncpy(to, from, sizeof(to))
|
|
#define safestrcpymax(to, from, max) my_strncpy(to, from, max)
|
|
|
|
-#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
|
|
+extern char *my_strncat(char *to, const char *from, size_t max);
|
|
+#define safestrcat(to, from) my_strncat(to, from, sizeof(to) - strlen(to) - 1)
|
|
|
|
#define safestrcatmax(to, from, max) \
|
|
do { \
|
|
diff --git a/lib/sysfs_utils.c b/lib/sysfs_utils.c
|
|
index 43df36fb972c..bd6f9c1b082b 100644
|
|
--- a/lib/sysfs_utils.c
|
|
+++ b/lib/sysfs_utils.c
|
|
@@ -152,12 +152,10 @@ int sysfs_get_link(const char *path, char *target, size_t len)
|
|
else if (*(d+1) == '.')
|
|
goto parse_path;
|
|
s = strrchr(temp_path, '/');
|
|
- if (s != NULL) {
|
|
- *(s+1) = '\0';
|
|
- safestrcat(temp_path, d);
|
|
- } else {
|
|
+ if (s != NULL)
|
|
+ safestrcpy(s+1, d);
|
|
+ else
|
|
safestrcpy(temp_path, d);
|
|
- }
|
|
safestrcpymax(target, temp_path, len);
|
|
break;
|
|
/*
|
|
@@ -187,12 +185,10 @@ parse_path:
|
|
/* relative path from this directory */
|
|
safestrcpy(temp_path, devdir);
|
|
s = strrchr(temp_path, '/');
|
|
- if (s != NULL) {
|
|
- *(s+1) = '\0';
|
|
- safestrcat(temp_path, linkpath);
|
|
- } else {
|
|
+ if (s != NULL)
|
|
+ safestrcpy(s+1, linkpath);
|
|
+ else
|
|
safestrcpy(temp_path, linkpath);
|
|
- }
|
|
safestrcpymax(target, temp_path, len);
|
|
}
|
|
return 0;
|
|
@@ -321,3 +317,16 @@ char *my_strncpy(char *to, const char *from, size_t max)
|
|
to[max-1] = '\0';
|
|
return to;
|
|
}
|
|
+
|
|
+/**
|
|
+ * my_strncpy -- a safe strncpy
|
|
+ */
|
|
+char *my_strncat(char *to, const char *from, size_t max)
|
|
+{
|
|
+ size_t i = 0;
|
|
+
|
|
+ while (i < max && to[i] != '\0')
|
|
+ i++;
|
|
+ my_strncpy(to+i, from, max-i);
|
|
+ return to;
|
|
+}
|
|
--
|
|
2.26.2
|
|
|