]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
ras-report: avoid copying after addr.sun_path
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Tue, 14 Aug 2018 16:10:10 +0000 (13:10 -0300)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Tue, 14 Aug 2018 16:10:10 +0000 (13:10 -0300)
As warned by gcc:

ras-report.c: In function ‘setup_report_socket’:
ras-report.c:36:2: warning: ‘strncpy’ output truncated before terminating nul copying 25 bytes from a string of the same length [-Wstringop-truncation]
  strncpy(addr.sun_path, ABRT_SOCKET, strlen(ABRT_SOCKET));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The strncpy logic there is wrong. Fix it and be sure to have a NUL
terminated string filled at addr.sun_path.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
ras-report.c

index d4beee079b4dcbc9adbc2efba74213abc97130c9..cb0a9e83e21d183b4990c8af6c10bdf54bbe1bee 100644 (file)
@@ -33,7 +33,8 @@ static int setup_report_socket(void){
 
        memset(&addr, 0, sizeof(struct sockaddr_un));
        addr.sun_family = AF_UNIX;
-       strncpy(addr.sun_path, ABRT_SOCKET, strlen(ABRT_SOCKET));
+       strncpy(addr.sun_path, ABRT_SOCKET, sizeof(addr.sun_path));
+       addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
 
        rc = connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un));
        if (rc < 0){