Rajaram-Regupathy / libtypec

“libtypec” is aimed to provide a generic interface abstracting all platform complexity for user space to develop tools for efficient USB-C port management. The library can also enable development of diagnostic and debug tools to debug system issues around USB-C/USB PD topology.
34 stars 4 forks source link

unitilized variable "event" in function libtypec_lnx_monitor_udev_events #35

Open ColinIanKing opened 2 months ago

ColinIanKing commented 2 months ago

In function libtypec_lnx_monitor_udev_events() variable event is uninitialized, hence it contains garbage and it is later used to index into an array. Static analysis shows:

1089    while (1) {
1090        struct udev_device *dev = udev_monitor_receive_device(mon);
1091        if (dev) {
1092            const char *subsystem = udev_device_get_subsystem(dev);

**var_decl: Declaring variable event without initializer.**

1093            enum usb_typec_event event;
1094            if (strcmp(subsystem, "typec") == 0) {
1095                // typec event
1096                const char *action = udev_device_get_action(dev);
1097                if (strcmp(action, "add") == 0) {
1098                    event = USBC_DEVICE_CONNECTED;
1099                } else if (strcmp(action, "remove") == 0) {
1100                    event = USBC_DEVICE_DISCONNECTED;
1101                }
1102            }
1103            udev_device_unref(dev);
1104
1105            // call all callbacks for this event

**uninit_use: Using uninitialized value event.**

1106            libtypec_notification_list_t* node = registered_callbacks[event];