Skip to content

Commit aa77dfc

Browse files
quic-bjorandeandersson
authored andcommitted
qdl: Allow absolute paths in Windows again
Commit '5b768d8be070 ("qdl: Allow multiple Sahara images")' introduced support for specifying multiple programmer images, by splitting the requested programmer on ':'-character and use the pair as id and filename specifiers. This obviously breaks absolute paths in Windows. Reorder the programmer decoder such that if the specifier starts with an id followed by a ':', then the specifier must be a comma-separated list of id:filename (where ',' is not allowed in the filename). In all other cases consider the whole specifier the one file to use as programmer, programmer archive, or programmer specifier XML. This brings back the ability to specify programmer by absolute path in Windows. The parsing of the programmer specifier is also altered to not tokenize on ':' but instead only find the first one and then treat the rest as the filename. This makes it possible use absolute paths here as well. Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
1 parent 22a43e2 commit aa77dfc

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

qdl.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,33 @@ static int decode_programmer(char *s, struct sahara_image *images, bool *single)
364364
{
365365
char *filename;
366366
char *save1;
367-
char *save2;
368367
char *pair;
369-
char *id_str;
368+
char *tail;
370369
long id;
371370
int ret;
372371

373-
if (!strchr(s, ':')) {
372+
strtoul(s, &tail, 0);
373+
if (tail != s && tail[0] == ':') {
374+
for (pair = strtok_r(s, ",", &save1); pair; pair = strtok_r(NULL, ",", &save1)) {
375+
id = strtoul(pair, &tail, 0);
376+
if (tail == pair) {
377+
ux_err("invalid programmer specifier\n");
378+
return -1;
379+
}
380+
381+
if (id == 0 || id >= MAPPING_SZ) {
382+
ux_err("invalid image id \"%s\"\n", pair);
383+
return -1;
384+
}
385+
386+
filename = &tail[1];
387+
ret = load_sahara_image(filename, &images[id]);
388+
if (ret < 0)
389+
return -1;
390+
391+
*single = false;
392+
}
393+
} else {
374394
ret = load_sahara_image(s, &images[0]);
375395
if (ret < 0)
376396
return -1;
@@ -386,32 +406,8 @@ static int decode_programmer(char *s, struct sahara_image *images, bool *single)
386406
}
387407

388408
*single = (ret == 0);
389-
390-
return 0;
391409
}
392410

393-
for (pair = strtok_r(s, ",", &save1); pair; pair = strtok_r(NULL, ",", &save1)) {
394-
id_str = strtok_r(pair, ":", &save2);
395-
filename = strtok_r(NULL, ":", &save2);
396-
397-
if (!id_str || !filename) {
398-
ux_err("failed to parse programmer specifier\n");
399-
return -1;
400-
}
401-
402-
id = strtoul(id_str, NULL, 0);
403-
if (id == 0 || id >= MAPPING_SZ) {
404-
ux_err("invalid image id \"%s\"\n", id_str);
405-
return -1;
406-
}
407-
408-
ret = load_sahara_image(filename, &images[id]);
409-
if (ret < 0)
410-
return -1;
411-
}
412-
413-
*single = false;
414-
415411
return 0;
416412
}
417413

0 commit comments

Comments
 (0)