Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/abi stack buffer overflow #100

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions include/usbg/function/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ union usbg_f_hid_attr_val {
unsigned int subclass;
};

#define USBG_F_HID_UINT_TO_ATTR_VAL(WHAT) \
USBG_TO_UNION(usbg_f_hid_attr_val, protocol, WHAT)

#define USBG_F_HID_RDESC_TO_ATTR_VAL(WHAT) \
USBG_TO_UNION(usbg_f_hid_attr_val, report_desc, WHAT)
/**
* @brief Cast from generic function to hid function
* @param[in] f function to be converted to hid funciton.
Expand Down Expand Up @@ -137,7 +132,7 @@ int usbg_f_hid_get_attr_val(usbg_f_hid *hf, enum usbg_f_hid_attr attr,
* @return 0 on success usbg_error if error occurred.
*/
int usbg_f_hid_set_attr_val(usbg_f_hid *hf, enum usbg_f_hid_attr attr,
union usbg_f_hid_attr_val val);
const union usbg_f_hid_attr_val *val);

/**
* @brief Get the minor and major of corresponding character device
Expand Down Expand Up @@ -173,8 +168,9 @@ static inline int usbg_f_hid_get_protocol(usbg_f_hid *hf,
static inline int usbg_f_hid_set_protocol(usbg_f_hid *hf,
unsigned int protocol)
{
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_PROTOCOL,
USBG_F_HID_UINT_TO_ATTR_VAL(protocol));

union usbg_f_hid_attr_val val = {.protocol = protocol};
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_PROTOCOL, &val);
}

/**
Expand All @@ -199,8 +195,8 @@ static inline int usbg_f_hid_get_report_desc(usbg_f_hid *hf,
static inline int usbg_f_hid_set_report_desc(usbg_f_hid *hf,
struct usbg_f_hid_report_desc report_desc)
{
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC,
USBG_F_HID_RDESC_TO_ATTR_VAL(report_desc));
union usbg_f_hid_attr_val val = {.report_desc = report_desc};
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC, &val);
}

/**
Expand Down Expand Up @@ -242,8 +238,8 @@ static inline int usbg_f_hid_set_report_desc_raw(usbg_f_hid *hf,
.len = len,
};

return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC,
USBG_F_HID_RDESC_TO_ATTR_VAL(report_desc));
union usbg_f_hid_attr_val val = {.report_desc = report_desc};
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC, &val);
}

/**
Expand All @@ -268,8 +264,8 @@ static inline int usbg_f_hid_get_report_length(usbg_f_hid *hf,
static inline int usbg_f_hid_set_report_length(usbg_f_hid *hf,
unsigned int report_length)
{
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_LENGTH,
USBG_F_HID_UINT_TO_ATTR_VAL(report_length));
union usbg_f_hid_attr_val val = {.report_length = report_length};
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_LENGTH, &val);
}

/**
Expand All @@ -294,8 +290,8 @@ static inline int usbg_f_hid_get_subclass(usbg_f_hid *hf,
static inline int usbg_f_hid_set_subclass(usbg_f_hid *hf,
unsigned int subclass)
{
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_SUBCLASS,
USBG_F_HID_UINT_TO_ATTR_VAL(subclass));
union usbg_f_hid_attr_val val = {.subclass = subclass};
return usbg_f_hid_set_attr_val(hf, USBG_F_HID_SUBCLASS, &val);
}

#ifdef __cplusplus
Expand Down
38 changes: 14 additions & 24 deletions include/usbg/function/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ union usbg_f_midi_attr_val {
unsigned int qlen;
};

#define USBG_F_MIDI_INT_TO_ATTR_VAL(WHAT) \
USBG_TO_UNION(usbg_f_midi_attr_val, index, WHAT)

#define USBG_F_MIDI_UINT_TO_ATTR_VAL(WHAT) \
USBG_TO_UNION(usbg_f_midi_attr_val, qlen, WHAT)

#define USBG_F_MIDI_CCHAR_PTR_TO_ATTR_VAL(WHAT) \
USBG_TO_UNION(usbg_f_midi_attr_val, id, WHAT)

/**
* @brief Cast from generic function to midi function
* @param[in] f function to be converted to midi funciton.
Expand Down Expand Up @@ -126,7 +117,7 @@ int usbg_f_midi_get_attr_val(usbg_f_midi *mf, enum usbg_f_midi_attr attr,
* @return 0 on success usbg_error if error occurred.
*/
int usbg_f_midi_set_attr_val(usbg_f_midi *mf, enum usbg_f_midi_attr attr,
union usbg_f_midi_attr_val val);
const union usbg_f_midi_attr_val *val);

/**
* @brief Get the index value of MIDI adapter
Expand All @@ -148,8 +139,8 @@ static inline int usbg_f_midi_get_index(usbg_f_midi *mf, int *index)
*/
static inline int usbg_f_midi_set_index(usbg_f_midi *mf, int index)
{
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_INDEX,
USBG_F_MIDI_INT_TO_ATTR_VAL(index));
union usbg_f_midi_attr_val val = {.index = index};
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_INDEX, &val);
}

/**
Expand Down Expand Up @@ -188,14 +179,13 @@ int usbg_f_midi_get_id_s(usbg_f_midi *mf, char *buf, int len);
*/
static inline int usbg_f_midi_set_id(usbg_f_midi *mf, const char *id)
{
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_ID,
USBG_F_MIDI_CCHAR_PTR_TO_ATTR_VAL(id));
union usbg_f_midi_attr_val val = {.id = id};
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_ID, &val);
}

/**
* @brief Get the number of in ports of MIDI adapter
* @param[in] mf Pointer to midi function
* @param[out] in_ports Number of in ports of MIDI adapter
* @param[in] mf Pointer to midi function * @param[out] in_ports Number of in ports of MIDI adapter
* @return 0 on success usbg_error if error occurred.
*/
static inline int usbg_f_midi_get_in_ports(usbg_f_midi *mf, unsigned *in_ports)
Expand All @@ -212,8 +202,8 @@ static inline int usbg_f_midi_get_in_ports(usbg_f_midi *mf, unsigned *in_ports)
*/
static inline int usbg_f_midi_set_in_ports(usbg_f_midi *mf, unsigned in_ports)
{
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_IN_PORTS,
USBG_F_MIDI_UINT_TO_ATTR_VAL(in_ports));
union usbg_f_midi_attr_val val = {.in_ports = in_ports};
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_IN_PORTS, &val);
}

/**
Expand All @@ -236,8 +226,8 @@ static inline int usbg_f_midi_get_out_ports(usbg_f_midi *mf, unsigned *out_ports
*/
static inline int usbg_f_midi_set_out_ports(usbg_f_midi *mf, unsigned out_ports)
{
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_OUT_PORTS,
USBG_F_MIDI_UINT_TO_ATTR_VAL(out_ports));
union usbg_f_midi_attr_val val = {.out_ports = out_ports};
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_OUT_PORTS, &val);
}

/**
Expand All @@ -264,8 +254,8 @@ static inline int usbg_f_midi_get_buflen(usbg_f_midi *mf, int *buflen)
*/
static inline int usbg_f_midi_set_buflen(usbg_f_midi *mf, unsigned buflen)
{
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_BUFLEN,
USBG_F_MIDI_UINT_TO_ATTR_VAL(buflen));
union usbg_f_midi_attr_val val = {.buflen = buflen};
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_BUFLEN, &val);
}

/**
Expand All @@ -288,8 +278,8 @@ static inline int usbg_f_midi_get_qlen(usbg_f_midi *mf, unsigned *qlen)
*/
static inline int usbg_f_midi_set_qlen(usbg_f_midi *mf, unsigned qlen)
{
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_QLEN,
USBG_F_MIDI_UINT_TO_ATTR_VAL(qlen));
union usbg_f_midi_attr_val val = {.qlen = qlen};
return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_QLEN, &val);
}

#ifdef __cplusplus
Expand Down
34 changes: 13 additions & 21 deletions include/usbg/function/ms.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ union usbg_f_ms_lun_attr_val {
const char *inquiry_string;
};

#define USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(WHAT) \
USBG_TO_UNION(usbg_f_ms_lun_attr_val, cdrom, WHAT)

#define USBG_F_MS_LUN_CCHAR_PTR_TO_ATTR_VAL(WHAT) \
USBG_TO_UNION(usbg_f_ms_lun_attr_val, file, WHAT)



/**
* @brief Cast from generic function to mass storage function
* @param[in] f function to be converted to ms funciton.
Expand Down Expand Up @@ -162,7 +154,7 @@ int usbg_f_ms_get_lun_attr_val(usbg_f_ms *mf, int lun_id,
*/
int usbg_f_ms_set_lun_attr_val(usbg_f_ms *mf, int lun_id,
enum usbg_f_ms_lun_attr lattr,
const union usbg_f_ms_lun_attr_val val);
const union usbg_f_ms_lun_attr_val *val);

/**
* @brief Get the value which determines if lun is visible as a cdrom
Expand All @@ -188,8 +180,8 @@ static inline int usbg_f_ms_get_lun_cdrom(usbg_f_ms *mf, int lun_id,
static inline int usbg_f_ms_set_lun_cdrom(usbg_f_ms *mf, int lun_id,
bool cdrom)
{
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_CDROM,
USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(cdrom));
union usbg_f_ms_lun_attr_val val = {.cdrom = cdrom};
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_CDROM, &val);
}

/**
Expand All @@ -214,8 +206,8 @@ static inline int usbg_f_ms_get_lun_ro(usbg_f_ms *mf, int lun_id, bool *ro)
*/
static inline int usbg_f_ms_set_lun_ro(usbg_f_ms *mf, int lun_id, bool ro)
{
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_RO,
USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(ro));
union usbg_f_ms_lun_attr_val val = {.ro = ro};
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_RO, &val);
}

/**
Expand Down Expand Up @@ -244,8 +236,8 @@ static inline int usbg_f_ms_get_lun_nofua(usbg_f_ms *mf, int lun_id,
static inline int usbg_f_ms_set_lun_nofua(usbg_f_ms *mf, int lun_id,
bool nofua)
{
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_NOFUA,
USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(nofua));
union usbg_f_ms_lun_attr_val val = {.nofua = nofua};
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_NOFUA, &val);
}

/**
Expand All @@ -272,8 +264,8 @@ static inline int usbg_f_ms_get_lun_removable(usbg_f_ms *mf, int lun_id,
static inline int usbg_f_ms_set_lun_removable(usbg_f_ms *mf, int lun_id,
bool removable)
{
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_REMOVABLE,
USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(removable));
union usbg_f_ms_lun_attr_val val = {.removable = removable};
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_REMOVABLE, &val);
}

/**
Expand Down Expand Up @@ -318,8 +310,8 @@ int usbg_f_ms_get_lun_file_s(usbg_f_ms *mf, int lun_id,
static inline int usbg_f_ms_set_lun_file(usbg_f_ms *mf, int lun_id,
const char *file)
{
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_FILE,
USBG_F_MS_LUN_CCHAR_PTR_TO_ATTR_VAL(file));
union usbg_f_ms_lun_attr_val val = {.file = file};
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_FILE, &val);
}

/**
Expand Down Expand Up @@ -349,8 +341,8 @@ static inline int usbg_f_ms_get_lun_inquiry_string(usbg_f_ms *mf, int lun_id,
static inline int usbg_f_ms_set_lun_inquiry_string(usbg_f_ms *mf, int lun_id,
const char *inquiry_string)
{
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_INQUIRY_STRING,
USBG_F_MS_LUN_CCHAR_PTR_TO_ATTR_VAL(inquiry_string));
union usbg_f_ms_lun_attr_val val = {.inquiry_string = inquiry_string};
return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_INQUIRY_STRING, &val);
}

/**
Expand Down
Loading