[PATCH] Make efibootguard compatible to gcc 8.1

2 views
Skip to first unread message

Andreas J. Reichel

unread,
May 7, 2018, 7:09:32 AM5/7/18
to efibootg...@googlegroups.com, jan.k...@siemens.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

GCC 8.1 has some additional `intelligent` tests, that do not allow the
length parameter in `strncat` or `strncpy` to be dependent on the
source. Despite the buffer being surely large enough, it complains with

error: 'strncpy' specified bound depends on the length of the
source argument [-Werror=stringop-overflow=].

Fact is, that all the functions that are used like this in the code
behave exactly as their counterpart `strcat` or `strcpy` respectively.
Hence, the solution is to just use strcat and strcpy.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>
---
env/env_api_fat.c | 2 +-
env/env_config_file.c | 7 +++----
env/env_disk_utils.c | 5 ++---
env/uservars.c | 2 +-
4 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 1795259..378b20e 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -264,7 +264,7 @@ static int bgenv_get_string(char *buffer, uint64_t *type, void *data,
if (!data) {
return strlen(buffer)+1;
}
- strncpy(data, buffer, strlen(buffer)+1);
+ strcpy(data, buffer);
if (type) {
*type = USERVAR_TYPE_STRING_ASCII;
}
diff --git a/env/env_config_file.c b/env/env_config_file.c
index 7f817cb..873fe10 100644
--- a/env/env_config_file.c
+++ b/env/env_config_file.c
@@ -30,10 +30,9 @@ FILE *open_config_file(CONFIG_PART *cfgpart, char *mode)
if (!configfilepath) {
return NULL;
}
- strncpy(configfilepath, cfgpart->mountpoint,
- strlen(cfgpart->mountpoint) + 1);
- strncat(configfilepath, "/", 1);
- strncat(configfilepath, FAT_ENV_FILENAME, strlen(FAT_ENV_FILENAME));
+ strcpy(configfilepath, cfgpart->mountpoint);
+ strcat(configfilepath, "/");
+ strcat(configfilepath, FAT_ENV_FILENAME);
VERBOSE(stdout, "Probing config file at %s.\n", configfilepath);
FILE *config = fopen(configfilepath, mode);
free(configfilepath);
diff --git a/env/env_disk_utils.c b/env/env_disk_utils.c
index fae3812..30c2861 100644
--- a/env/env_disk_utils.c
+++ b/env/env_disk_utils.c
@@ -39,8 +39,7 @@ char *get_mountpoint(char *devpath)
if (!mntpoint) {
break;
}
- strncpy(mntpoint, part->mnt_dir,
- strlen(part->mnt_dir) + 1);
+ strcpy(mntpoint, part->mnt_dir);
return mntpoint;
}
}
@@ -77,7 +76,7 @@ bool mount_partition(CONFIG_PART *cfgpart)
VERBOSE(stderr, "Error, out of memory.\n");
return false;
}
- strncpy(cfgpart->mountpoint, mountpoint, strlen(mountpoint) + 1);
+ strcpy(cfgpart->mountpoint, mountpoint);
return true;
}

diff --git a/env/uservars.c b/env/uservars.c
index aa05235..daa757d 100644
--- a/env/uservars.c
+++ b/env/uservars.c
@@ -78,7 +78,7 @@ void bgenv_serialize_uservar(uint8_t *p, char *key, uint64_t type, void *data,
uint32_t payload_size, data_size;

/* store key */
- strncpy((char *)p, key, strlen(key) + 1);
+ strcpy((char *)p, key);
p += strlen(key) + 1;

/* store payload_size after key */
--
2.17.0

Jan Kiszka

unread,
May 7, 2018, 7:17:38 AM5/7/18
to Andreas J. Reichel, efibootg...@googlegroups.com
On 2018-05-07 13:05, Andreas J. Reichel wrote:
> From: Andreas Reichel <andreas.r...@siemens.com>
>
> GCC 8.1 has some additional `intelligent` tests, that do not allow the
> length parameter in `strncat` or `strncpy` to be dependent on the
> source. Despite the buffer being surely large enough, it complains with
>
> error: 'strncpy' specified bound depends on the length of the
> source argument [-Werror=stringop-overflow=].
>
> Fact is, that all the functions that are used like this in the code
> behave exactly as their counterpart `strcat` or `strcpy` respectively.
> Hence, the solution is to just use strcat and strcpy.

And that will not raise some other warnings of the kind "potentially
unbounded copying"?

How about using strdup in cases where we really just copy the string?

Jan
Reply all
Reply to author
Forward
0 new messages