Skip to content

Commit bc7fff7

Browse files
committed
mctp-client: use parse_* helpers for argument parsing
We have helpers for EID and net parsing, use those instead of an explicit stroul(). This means we don't need to carry parse status outside of individual tag handler blocks. In doing so, fix a bug where network IDs > 255 are not accepted. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent ce7d759 commit bc7fff7

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/mctp-client.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,11 @@ static int find_data(int argc, char **argv)
209209

210210
int main(int argc, char **argv)
211211
{
212-
int ctr, data_idx, net = MCTP_NET_ANY;
212+
unsigned int net = MCTP_NET_ANY;
213213
bool valid_eid, valid_type;
214214
struct data_t send_data;
215-
char *tag, *endp, *val;
216-
unsigned long int tmp;
215+
int type, ctr, data_idx;
217216
mctp_eid_t eid;
218-
int type;
219217

220218
data_idx = find_data(argc, argv);
221219
if (data_idx < 0) {
@@ -235,33 +233,29 @@ int main(int argc, char **argv)
235233
valid_type = false;
236234

237235
for (ctr = 1; ctr < argc; ctr += 2) {
238-
bool valid_parse;
236+
char *tag, *val;
237+
int rc;
239238

240239
tag = argv[ctr];
241240
val = argv[ctr + 1];
242-
tmp = strtoul(val, &endp, 0);
243-
valid_parse = endp != val;
241+
244242
if (!strcmp(tag, "eid")) {
245-
if (tmp > 0xff)
243+
rc = parse_eid(val, &eid);
244+
if (rc)
246245
errx(EXIT_FAILURE, "invalid eid: %s", val);
247-
eid = tmp;
248246
valid_eid = true;
249247
} else if (!strcmp(tag, "net")) {
250-
if (net > 0xff)
248+
rc = parse_uint32(val, &net);
249+
if (rc)
251250
errx(EXIT_FAILURE, "invalid net: %s", val);
252-
net = tmp;
253251
} else if (!strcmp(tag, "type")) {
254252
type = do_type_lookup(val);
255253
if (type < 0 || type > 0xff)
256254
errx(EXIT_FAILURE, "invalid type: %s", val);
257-
258-
valid_parse = true;
259255
valid_type = true;
256+
260257
} else
261258
errx(EXIT_FAILURE, "invalid tag: %s", tag);
262-
263-
if (!valid_parse)
264-
errx(EXIT_FAILURE, "invalid argument: %s", val);
265259
}
266260

267261
if (!valid_eid || !valid_type) {

0 commit comments

Comments
 (0)