OSDN Git Service

Avoid possible buffer overflow.
authorElliott Hughes <enh@google.com>
Fri, 19 Jan 2018 23:53:14 +0000 (15:53 -0800)
committerElliott Hughes <enh@google.com>
Fri, 19 Jan 2018 23:53:14 +0000 (15:53 -0800)
clang-tidy rightly complains that this code for concatenating two strings
is incorrect because it doesn't take into account the space used by the
first string when appending the second string. Just use snprintf instead.

Bug: N/A
Test: builds, boots
Change-Id: Ifdaff43a87301a876369635013516aab41cd48c3

rild/rild.c

index dbd925d..685ef70 100644 (file)
@@ -144,8 +144,8 @@ int main(int argc, char **argv) {
         exit(0);
     }
     if (strncmp(clientId, "0", MAX_CLIENT_ID_LENGTH)) {
-        strncpy(ril_service_name, ril_service_name_base, MAX_SERVICE_NAME_LENGTH);
-        strncat(ril_service_name, clientId, MAX_SERVICE_NAME_LENGTH);
+        snprintf(ril_service_name, sizeof(ril_service_name), "%s%s", ril_service_name_base,
+                 clientId);
     }
 
     if (rilLibPath == NULL) {