On Mon, May 07, 2018 at 02:01:55PM +0200, Andreas J. Reichel wrote:
Sorry, copied wrong message-id to git send-email.

> 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.
> 
> Instead of malloc and strcpy, strdup can be used.
> 
> Signed-off-by: Andreas Reichel <[email protected]>
> ---
>  env/env_api_fat.c     | 2 +-
>  env/env_config_file.c | 7 +++----
>  env/env_disk_utils.c  | 6 ++----
>  env/uservars.c        | 2 +-
>  4 files changed, 7 insertions(+), 10 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..9fad94b 100644
> --- a/env/env_disk_utils.c
> +++ b/env/env_disk_utils.c
> @@ -35,12 +35,10 @@ char *get_mountpoint(char *devpath)
>                   (strcmp(part->mnt_fsname, devpath)) == 0) {
>                       char *mntpoint;
>  
> -                     mntpoint = malloc(strlen(part->mnt_dir) + 1);
> +                     mntpoint = strdup(part->mnt_dir);
>                       if (!mntpoint) {
>                               break;
>                       }
> -                     strncpy(mntpoint, part->mnt_dir,
> -                             strlen(part->mnt_dir) + 1);
>                       return mntpoint;
>               }
>       }
> @@ -77,7 +75,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
> 

-- 
Andreas Reichel
Dipl.-Phys. (Univ.)
Software Consultant

[email protected], +49-174-3180074
TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterfoehring
Geschaeftsfuehrer: Henrik Klagges, Dr. Robert Dahlke, Gerhard Mueller
Sitz: Unterfoehring * Amtsgericht Muenchen * HRB 135082

-- 
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/20180507120540.GA8585%40iiotirae.
For more options, visit https://groups.google.com/d/optout.

Reply via email to