Issues were reported by GCC 8.2 and the stringop-overflow option.

Signed-off-by: Pascal Bach <[email protected]>
---
 env/env_api_fat.c     | 2 +-
 env/env_config_file.c | 6 +++---
 env/env_disk_utils.c  | 4 ++--
 env/uservars.c        | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 1795259..120bd10 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);
+       strncpy(data, buffer, strlen(data)+1);
        if (type) {
                *type = USERVAR_TYPE_STRING_ASCII;
        }
diff --git a/env/env_config_file.c b/env/env_config_file.c
index 7f817cb..fc80a65 100644
--- a/env/env_config_file.c
+++ b/env/env_config_file.c
@@ -31,9 +31,9 @@ FILE *open_config_file(CONFIG_PART *cfgpart, char *mode)
                return NULL;
        }
        strncpy(configfilepath, cfgpart->mountpoint,
-               strlen(cfgpart->mountpoint) + 1);
-       strncat(configfilepath, "/", 1);
-       strncat(configfilepath, FAT_ENV_FILENAME, strlen(FAT_ENV_FILENAME));
+               strlen(configfilepath) + 1);
+       strncat(configfilepath, "/", sizeof(configfilepath) - strlen("/") - 1);
+       strncat(configfilepath, FAT_ENV_FILENAME, sizeof(configfilepath) - 
strlen(FAT_ENV_FILENAME) - 1);
        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..f2699df 100644
--- a/env/env_disk_utils.c
+++ b/env/env_disk_utils.c
@@ -40,7 +40,7 @@ char *get_mountpoint(char *devpath)
                                break;
                        }
                        strncpy(mntpoint, part->mnt_dir,
-                               strlen(part->mnt_dir) + 1);
+                               strlen(mntpoint) + 1);
                        return mntpoint;
                }
        }
@@ -77,7 +77,7 @@ bool mount_partition(CONFIG_PART *cfgpart)
                VERBOSE(stderr, "Error, out of memory.\n");
                return false;
        }
-       strncpy(cfgpart->mountpoint, mountpoint, strlen(mountpoint) + 1);
+       strncpy(cfgpart->mountpoint, mountpoint, strlen(cfgpart->mountpoint) + 
1);
        return true;
 }
 
diff --git a/env/uservars.c b/env/uservars.c
index aa05235..ed721a3 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);
+       strncpy((char *)p, key, strlen((char *)p) + 1);
        p += strlen(key) + 1;
 
        /* store payload_size after key */
-- 
2.11.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/20180829132503.30154-1-pascal.bach%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to