]> sigrok.org Git - libsigrok.git/commitdiff
asix-sigma: check sdi before dereferencing a NULL pointer
authorGerhard Sittig <redacted>
Wed, 31 Aug 2022 15:37:05 +0000 (09:37 -0600)
committerGerhard Sittig <redacted>
Mon, 12 Sep 2022 16:28:36 +0000 (18:28 +0200)
The asix-sigma config_list() routine unconditionally dereferenced the
'sdi' pointer, which could be NULL. Properly check before dereferencing.
This issue was introduced in commit eabf9ca630f4. How to reproduce:

  $ sigrok-cli -d asix-sigma --show

Reported-By: Paul Kasemir <redacted>
src/hardware/asix-sigma/api.c

index 72da2c1476366f946a997294eabfeb3a1378097b..f1b96bb79fdd16eb489792989e7dbc486323efdc 100644 (file)
@@ -401,7 +401,7 @@ static int config_list(uint32_t key, GVariant **data,
        const char **names;
        size_t count;
 
-       devc = sdi->priv;
+       devc = sdi ? sdi->priv : NULL;
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
        case SR_CONF_DEVICE_OPTIONS:
@@ -413,6 +413,8 @@ static int config_list(uint32_t key, GVariant **data,
                *data = sigma_get_samplerates_list();
                break;
        case SR_CONF_EXTERNAL_CLOCK_SOURCE:
+               if (!devc)
+                       return SR_ERR_ARG;
                names = (const char **)devc->channel_names;
                count = g_strv_length(devc->channel_names);
                *data = g_variant_new_strv(names, count);