From 6e718159ce712910c6e712ad68390b4edcf606f7 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Fri, 10 Nov 2017 22:48:43 +0000 Subject: [PATCH] re PR c/81117 (Improve buffer overflow checking in strncpy) gcc/ChangeLog: PR c/81117 * config/darwin-c.c (framework_construct_pathname): Replace strncpy with memcpy. (find_subframework_file): Same. From-SVN: r254641 --- gcc/ChangeLog | 7 +++++++ gcc/config/darwin-c.c | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4ff82568cc4..4e50a888103 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-11-10 Martin Sebor + + PR c/81117 + * config/darwin-c.c (framework_construct_pathname): Replace strncpy + with memcpy. + (find_subframework_file): Same. + 2017-11-10 Jeff Law * vr-values.h (VR_INITIALIZER): Move #define here. diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c index 91f08a0dcee..bfb35b9ae6d 100644 --- a/gcc/config/darwin-c.c +++ b/gcc/config/darwin-c.c @@ -284,13 +284,13 @@ framework_construct_pathname (const char *fname, cpp_dir *dir) frname = XNEWVEC (char, strlen (fname) + dir->len + 2 + strlen(".framework/") + strlen("PrivateHeaders")); - strncpy (&frname[0], dir->name, dir->len); + memcpy (&frname[0], dir->name, dir->len); frname_len = dir->len; if (frname_len && frname[frname_len-1] != '/') frname[frname_len++] = '/'; - strncpy (&frname[frname_len], fname, fname_len); + memcpy (&frname[frname_len], fname, fname_len); frname_len += fname_len; - strncpy (&frname[frname_len], ".framework/", strlen (".framework/")); + memcpy (&frname[frname_len], ".framework/", strlen (".framework/")); frname_len += strlen (".framework/"); if (fast_dir == 0) @@ -316,7 +316,7 @@ framework_construct_pathname (const char *fname, cpp_dir *dir) /* Append framework_header_dirs and header file name */ for (i = 0; framework_header_dirs[i].dirName; i++) { - strncpy (&frname[frname_len], + memcpy (&frname[frname_len], framework_header_dirs[i].dirName, framework_header_dirs[i].dirNameLen); strcpy (&frname[frname_len + framework_header_dirs[i].dirNameLen], @@ -378,23 +378,23 @@ find_subframework_file (const char *fname, const char *pname) sfrname_len = bufptr - pname; - strncpy (&sfrname[0], pname, sfrname_len); + memcpy (&sfrname[0], pname, sfrname_len); - strncpy (&sfrname[sfrname_len], "Frameworks/", strlen ("Frameworks/")); + memcpy (&sfrname[sfrname_len], "Frameworks/", strlen ("Frameworks/")); sfrname_len += strlen("Frameworks/"); - strncpy (&sfrname[sfrname_len], fname, fname_len); + memcpy (&sfrname[sfrname_len], fname, fname_len); sfrname_len += fname_len; - strncpy (&sfrname[sfrname_len], ".framework/", strlen (".framework/")); + memcpy (&sfrname[sfrname_len], ".framework/", strlen (".framework/")); sfrname_len += strlen (".framework/"); /* Append framework_header_dirs and header file name */ for (i = 0; framework_header_dirs[i].dirName; i++) { - strncpy (&sfrname[sfrname_len], - framework_header_dirs[i].dirName, - framework_header_dirs[i].dirNameLen); + memcpy (&sfrname[sfrname_len], + framework_header_dirs[i].dirName, + framework_header_dirs[i].dirNameLen); strcpy (&sfrname[sfrname_len + framework_header_dirs[i].dirNameLen], &fname[fname_len]); -- 2.30.2