mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-26 17:31:45 +02:00
Ensure strncpy'ed strings are all null terminated
If there is no null byte among the first n bytes of the source the resulting string will not be properly null terminated. Ensure that all strings that are copied via strncpy are properly terminated copy "sizeof (dest) - 1" bytes and manually terminate the string in the cases the array was not initialized. Example compiler warning: ../daemon/gamemode-tests.c: In function ‘run_cpu_governor_tests’: ../daemon/gamemode-tests.c:326:4: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation] strncpy(defaultgov, currentgov, CONFIG_VALUE_MAX); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:

committed by
Alex Smith

parent
db4dd87e22
commit
bbde1d0357
@ -224,7 +224,8 @@ int game_mode_get_gpu(GameModeGPUInfo *info)
|
||||
}
|
||||
break;
|
||||
case Vendor_AMD:
|
||||
strncpy(info->amd_performance_level, buffer, CONFIG_VALUE_MAX);
|
||||
strncpy(info->amd_performance_level, buffer, sizeof(info->amd_performance_level) - 1);
|
||||
info->amd_performance_level[sizeof(info->amd_performance_level) - 1] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user