Skip to content

Commit

Permalink
Merge pull request #1055 from UltimateHackingKeyboard/fix_strcpy_size…
Browse files Browse the repository at this point in the history
…of_fail

Fix sizeof fails.
  • Loading branch information
mondalaci authored Dec 22, 2024
2 parents a982f36 + dd2839f commit eee7bce
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion right/src/usb_commands/usb_command_exec_macro_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ key_state_t dummyState;

static void requestExecution(const uint8_t *GenericHidOutBuffer)
{
Utils_SafeStrCopy(UsbMacroCommand, ((char*)GenericHidOutBuffer) + 1, sizeof(GenericHidOutBuffer)-1);
Utils_SafeStrCopy(UsbMacroCommand, ((char*)GenericHidOutBuffer) + 1, USB_GENERIC_HID_OUT_BUFFER_LENGTH - 1);
UsbMacroCommandLength = strlen(UsbMacroCommand);

EventVector_Set(EventVector_UsbMacroCommandWaitingForExecution);
Expand Down
4 changes: 2 additions & 2 deletions right/src/usb_commands/usb_command_get_device_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G
SetUsbTxBufferUint32(1, CurrentTime);
break;
case DevicePropertyId_GitTag:
Utils_SafeStrCopy(((char *)GenericHidInBuffer) + 1, gitTag, sizeof(GenericHidInBuffer) - 1);
Utils_SafeStrCopy(((char *)GenericHidInBuffer) + 1, gitTag, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1);
break;
case DevicePropertyId_GitRepo:
Utils_SafeStrCopy(
((char *)GenericHidInBuffer) + 1, gitRepo, sizeof(GenericHidInBuffer) - 1);
((char *)GenericHidInBuffer) + 1, gitRepo, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1);
break;
case DevicePropertyId_FirmwareChecksum: {
uint8_t moduleId = GetUsbRxBufferUint8(2);
Expand Down
4 changes: 2 additions & 2 deletions right/src/usb_commands/usb_command_get_module_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ void UsbCommand_GetModuleProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G
case ModulePropertyId_GitTag: {
uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId);
uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId;
Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitTag, sizeof(GenericHidInBuffer) - 1);
Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitTag, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1);
break;
}
case ModulePropertyId_GitRepo: {
uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId);
uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId;
Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitRepo, sizeof(GenericHidInBuffer) - 1);
Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitRepo, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1);
break;
}
case ModulePropertyId_FirmwareChecksum: {
Expand Down
3 changes: 2 additions & 1 deletion right/src/usb_commands/usb_command_get_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "usb_report_updater.h"
#include "macros/core.h"
#include "config_manager.h"
#include "usb_interfaces/usb_interface_generic_hid.h"

void UsbCommand_GetVariable(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer)
{
Expand All @@ -27,7 +28,7 @@ void UsbCommand_GetVariable(const uint8_t *GenericHidOutBuffer, uint8_t *Generic
SetUsbTxBufferUint8(1, UsbReportUpdateSemaphore);
break;
case UsbVariable_StatusBuffer:
for (uint8_t i = 1; i < sizeof(GenericHidInBuffer); i++) {
for (uint8_t i = 1; i < USB_GENERIC_HID_IN_BUFFER_LENGTH; i++) {
char c = Macros_ConsumeStatusChar();
SetUsbTxBufferUint8(i, c);
if (c == '\0') {
Expand Down

0 comments on commit eee7bce

Please sign in to comment.