aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-04-13 08:31:09 -0400
committerGitHub <noreply@github.com>2018-04-13 08:31:09 -0400
commit4dbf7f8b8832bb16940527c18765131f7bbf83b2 (patch)
tree262b21eac2b3c06047d697a81bd899ddcf09ed4b
parent65903d26775789608bb336ecde03259e94b3a6d7 (diff)
parent555206cf6041c0ab8c83f3a9860cd794a7be255c (diff)
Merge pull request #865 from martinetd/str_truncation
Fix gcc string truncation warnings
-rw-r--r--examples/support/config.c5
-rw-r--r--examples/support/ini.c2
-rw-r--r--include/wlr/types/wlr_output.h2
-rw-r--r--rootston/config.c5
-rw-r--r--rootston/ini.c2
5 files changed, 11 insertions, 5 deletions
diff --git a/examples/support/config.c b/examples/support/config.c
index f0efa594..319be31a 100644
--- a/examples/support/config.c
+++ b/examples/support/config.c
@@ -202,7 +202,10 @@ struct example_config *parse_args(int argc, char *argv[]) {
char cwd[MAXPATHLEN];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
char buf[MAXPATHLEN];
- snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "wlr-example.ini");
+ if (snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "wlr-example.ini") >= MAXPATHLEN) {
+ wlr_log(L_ERROR, "config path too long");
+ exit(1);
+ }
config->config_path = strdup(buf);
} else {
wlr_log(L_ERROR, "could not get cwd");
diff --git a/examples/support/ini.c b/examples/support/ini.c
index 6be9c44a..6bc1eae6 100644
--- a/examples/support/ini.c
+++ b/examples/support/ini.c
@@ -64,7 +64,7 @@ static char* find_chars_or_comment(const char* s, const char* chars)
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
static char* strncpy0(char* dest, const char* src, size_t size)
{
- strncpy(dest, src, size);
+ strncpy(dest, src, size-1);
dest[size - 1] = '\0';
return dest;
}
diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h
index cc03452d..cef3fc5d 100644
--- a/include/wlr/types/wlr_output.h
+++ b/include/wlr/types/wlr_output.h
@@ -55,7 +55,7 @@ struct wlr_output {
struct wl_global *wl_global;
struct wl_list wl_resources;
- char name[16];
+ char name[24];
char make[48];
char model[16];
char serial[16];
diff --git a/rootston/config.c b/rootston/config.c
index 0883f6d4..67bf83e9 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -418,7 +418,10 @@ struct roots_config *roots_config_create_from_args(int argc, char *argv[]) {
char cwd[MAXPATHLEN];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
char buf[MAXPATHLEN];
- snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "rootston.ini");
+ if (snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "rootston.ini") >= MAXPATHLEN) {
+ wlr_log(L_ERROR, "config path too long");
+ exit(1);
+ }
config->config_path = strdup(buf);
} else {
wlr_log(L_ERROR, "could not get cwd");
diff --git a/rootston/ini.c b/rootston/ini.c
index 56cc9ea6..f515dd38 100644
--- a/rootston/ini.c
+++ b/rootston/ini.c
@@ -64,7 +64,7 @@ static char* find_chars_or_comment(const char* s, const char* chars)
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
static char* strncpy0(char* dest, const char* src, size_t size)
{
- strncpy(dest, src, size);
+ strncpy(dest, src, size-1);
dest[size - 1] = '\0';
return dest;
}