소스 검색

Replaced strcopy with memmove (#2061)

Shortened the original title and commit message a little.
Thanks to @rpdigos!

Original commit message:
When we try to run the application we got the signal Abort trap 6 and the application is interrupted by the OS.
This issue is related with the fact that when using strncpy the source and destination string should not overlap, as we can see in the man page:

man stpncpy()
...
The source and destination strings should not overlap, as the behavior is undefined.

We've replaced it by the function memove:

man memmove()
...
The two strings may overlap; the copy is always done in a non-destructive manner.

Follow ec1fe15d7d480e4fa6ff3f56986bbfd49a4cde2a
rpdigos 8 년 전
부모
커밋
07e1a670bc
1개의 변경된 파일2개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 3
      src/map/map.c

+ 2 - 3
src/map/map.c

@@ -3990,9 +3990,8 @@ int inter_config_read(char *cfgName)
 #define RENEWALPREFIX "renewal-"
 		if (!strncmpi(w1, RENEWALPREFIX, strlen(RENEWALPREFIX))) {
 #ifdef RENEWAL
-			// Copy the original name
-			// Do not use safestrncpy here - enforces zero termination before copying and will break it [Lemongrass]
-			strncpy(w1, w1 + strlen(RENEWALPREFIX), strlen(w1) - strlen(RENEWALPREFIX) + 1);
+			// Move the original name to the beginning of the string
+			memmove(w1, w1 + strlen(RENEWALPREFIX), strlen(w1) - strlen(RENEWALPREFIX) + 1);
 #else
 			// In Pre-Renewal the Renewal specific configurations can safely be ignored
 			continue;