@@ -266,7 +266,7 @@ static int decode_programmer_archive(struct sahara_image *blob, struct sahara_im
266266 *
267267 * Returns: 0 if no archive was found, 1 if archive was decoded, -1 on error
268268 */
269- static int decode_sahara_config (struct sahara_image * blob , struct sahara_image * images )
269+ static int decode_sahara_config (struct sahara_image * blob , struct sahara_image * images , struct qdl_zip * zip )
270270{
271271 char image_path_full [PATH_MAX ];
272272 const char * image_path ;
@@ -294,6 +294,8 @@ static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *
294294 blob_name_buf = strdup (blob -> name );
295295 base_path = dirname (blob_name_buf );
296296 base_path_len = strlen (base_path );
297+ if (base_path_len == 1 && base_path [0 ] == '.' )
298+ base_path_len = 0 ;
297299
298300 root = xmlDocGetRootElement (doc );
299301 if (xmlStrcmp (root -> name , (xmlChar * )"sahara_config" )) {
@@ -328,7 +330,7 @@ static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *
328330
329331 image_path_len = strlen (image_path );
330332
331- if (path_is_absolute (image_path )) {
333+ if (path_is_absolute (image_path ) || base_path_len == 0 ) {
332334 if (image_path_len + 1 > PATH_MAX ) {
333335 free ((void * )image_path );
334336 goto err_free_doc ;
@@ -347,7 +349,7 @@ static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *
347349
348350 free ((void * )image_path );
349351
350- ret = load_sahara_image (NULL , image_path_full , & images [image_id ]);
352+ ret = load_sahara_image (zip , image_path_full , & images [image_id ]);
351353 if (ret < 0 )
352354 goto err_free_doc ;
353355 }
@@ -385,15 +387,12 @@ static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *
385387 * second case, each comma-separated entry will be split on ':' and the given
386388 * <filename> will be assigned to the @image entry indicated by the given <id>.
387389 *
388- * Memory is not allocated for the various strings, instead @s will be modified
389- * by the tokenizer and pointers to the individual parts will be stored in the
390- * @images array.
391- *
392390 * Returns: 0 on success, -1 otherwise.
393391 */
394- static int decode_programmer ( char * s , struct sahara_image * images )
392+ int load_programmers ( const char * s , struct sahara_image * images , struct qdl_zip * zip )
395393{
396394 struct sahara_image archive ;
395+ char * copy ;
397396 char * filename ;
398397 char * save1 ;
399398 char * pair ;
@@ -403,35 +402,46 @@ static int decode_programmer(char *s, struct sahara_image *images)
403402
404403 strtoul (s , & tail , 0 );
405404 if (tail != s && tail [0 ] == ':' ) {
406- for (pair = strtok_r (s , "," , & save1 ); pair ; pair = strtok_r (NULL , "," , & save1 )) {
405+ copy = strdup (s );
406+ if (!copy ) {
407+ ux_err ("internal error: unable to allocate memory for argument\n" );
408+ return -1 ;
409+ }
410+
411+ for (pair = strtok_r (copy , "," , & save1 ); pair ; pair = strtok_r (NULL , "," , & save1 )) {
407412 id = strtoul (pair , & tail , 0 );
408- if (tail == pair ) {
413+ if (tail == pair || * tail != ':' || tail [ 1 ] == '\0' ) {
409414 ux_err ("invalid programmer specifier\n" );
415+ free (copy );
410416 return -1 ;
411417 }
412418
413419 if (id == 0 || id >= MAPPING_SZ ) {
414420 ux_err ("invalid image id \"%s\"\n" , pair );
421+ free (copy );
415422 return -1 ;
416423 }
417424
418425 filename = & tail [1 ];
419- ret = load_sahara_image (NULL , filename , & images [id ]);
420- if (ret < 0 )
426+ ret = load_sahara_image (zip , filename , & images [id ]);
427+ if (ret < 0 ) {
428+ free (copy );
421429 return -1 ;
430+ }
422431 }
432+ free (copy );
423433 } else {
424- ret = load_sahara_image (NULL , s , & archive );
434+ ret = load_sahara_image (zip , s , & archive );
425435 if (ret < 0 )
426436 return -1 ;
427437
428438 ret = decode_programmer_archive (& archive , images );
429- if (ret < 0 || ret == 1 )
430- return ret ;
439+ if (ret != 0 )
440+ return ( ret == 1 ) ? 0 : -1 ;
431441
432- ret = decode_sahara_config (& archive , images );
433- if (ret < 0 || ret == 1 )
434- return ret ;
442+ ret = decode_sahara_config (& archive , images , zip );
443+ if (ret != 0 )
444+ return ( ret == 1 ) ? 0 : -1 ;
435445
436446 images [SAHARA_ID_EHOSTDL_IMG ] = archive ;
437447 }
@@ -823,7 +833,7 @@ static int qdl_flash(int argc, char **argv)
823833 * "flash" subcommand. Handling of "flash" happens in the loop below.
824834 */
825835 if (strcmp (argv [optind ], "flash" )) {
826- ret = decode_programmer (argv [optind ++ ], sahara_images );
836+ ret = load_programmers (argv [optind ++ ], sahara_images , NULL );
827837 if (ret < 0 )
828838 goto out_cleanup ;
829839 }
0 commit comments