From: Andreas Reichel <[email protected]> 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 <[email protected]> --- 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 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/20180507110514.5567-1-andreas.reichel.ext%40siemens.com. For more options, visit https://groups.google.com/d/optout.
