Skip to content

Commit cb01ccd

Browse files
committed
xml: Properly handle errors in setup_scan_element
It would previously silently ignore all errors. Signed-off-by: Paul Cercueil <[email protected]>
1 parent 906b8d0 commit cb01ccd

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

xml.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ static int add_attr_to_device(struct iio_device *dev, xmlNode *n, enum iio_attr_
8888
}
8989
}
9090

91-
static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
91+
static int setup_scan_element(struct iio_channel *chn, xmlNode *n)
9292
{
9393
xmlAttr *attr;
94+
int err;
9495

9596
for (attr = n->properties; attr; attr = attr->next) {
9697
const char *name = (const char *) attr->name,
@@ -102,12 +103,12 @@ static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
102103
errno = 0;
103104
value = strtoll(content, &end, 0);
104105
if (end == content || value < 0 || errno == ERANGE)
105-
return;
106+
return -EINVAL;
106107
chn->index = (long) value;
107108
} else if (!strcmp(name, "format")) {
108109
char e, s;
109110
if (strchr(content, 'X')) {
110-
iio_sscanf(content, "%ce:%c%u/%uX%u>>%u",
111+
err = iio_sscanf(content, "%ce:%c%u/%uX%u>>%u",
111112
#ifdef _MSC_BUILD
112113
&e, (unsigned int)sizeof(e),
113114
&s, (unsigned int)sizeof(s),
@@ -118,9 +119,11 @@ static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
118119
&chn->format.length,
119120
&chn->format.repeat,
120121
&chn->format.shift);
122+
if (err != 6)
123+
return -EINVAL;
121124
} else {
122125
chn->format.repeat = 1;
123-
iio_sscanf(content, "%ce:%c%u/%u>>%u",
126+
err = iio_sscanf(content, "%ce:%c%u/%u>>%u",
124127
#ifdef _MSC_BUILD
125128
&e, (unsigned int)sizeof(e),
126129
&s, (unsigned int)sizeof(s),
@@ -130,6 +133,8 @@ static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
130133
&chn->format.bits,
131134
&chn->format.length,
132135
&chn->format.shift);
136+
if (err != 5)
137+
return -EINVAL;
133138
}
134139
chn->format.is_be = e == 'b';
135140
chn->format.is_signed = (s == 's' || s == 'S');
@@ -143,7 +148,7 @@ static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
143148
value = strtof(content, &end);
144149
if (end == content || errno == ERANGE) {
145150
chn->format.with_scale = false;
146-
return;
151+
return -EINVAL;
147152
}
148153

149154
chn->format.with_scale = true;
@@ -153,6 +158,8 @@ static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
153158
name);
154159
}
155160
}
161+
162+
return 0;
156163
}
157164

158165
static struct iio_channel * create_channel(struct iio_device *dev, xmlNode *n)

0 commit comments

Comments
 (0)