Skip to content

Commit

Permalink
fix metalink 'size' field parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed Aug 2, 2024
1 parent 3394dc7 commit f01d8f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
34 changes: 18 additions & 16 deletions plugins/metalink/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ TDNFXmlParseData(
)
{
struct MetalinkElementInfo* elementInfo = (struct MetalinkElementInfo*)userData;
char *size = NULL;

if(!elementInfo || !elementInfo->ml_ctx || IsNullOrEmptyString(elementInfo->filename) || elementInfo->dwError)
{
Expand All @@ -467,28 +466,33 @@ TDNFXmlParseData(
BAIL_ON_TDNF_ERROR(dwError);
}

if (elementInfo->startElement == NULL)
return;

if(!strcmp(elementInfo->startElement, TAG_NAME_FILE))
{
elementInfo->dwError = TDNFParseFileTag(userData);
BAIL_ON_TDNF_ERROR(elementInfo->dwError);
}
else if(!strcmp(elementInfo->startElement, TAG_NAME_SIZE))
{
//Get File Size.
TDNFAllocateStringN(val, len, &size);

if(!size)
{
/* 12-1 chars is sufficient to hold a file size in decimal digits */
char size_buf[12], *p = size_buf;
const char *q = val;

while (*q &&
q < val + len &&
p < size_buf + sizeof(size_buf) - 1 &&
isdigit(*q))
*p++ = *q++;
*p = 0;

if (!size_buf[0]) {
elementInfo->dwError = ERROR_TDNF_METALINK_PARSER_MISSING_FILE_SIZE;
pr_err("XML Parser Error:File size is missing: %s", size);
BAIL_ON_TDNF_ERROR(elementInfo->dwError);
}
if(sscanf(size, "%ld", &(elementInfo->ml_ctx->size)) != 1)
{
elementInfo->dwError = ERROR_TDNF_INVALID_PARAMETER;
pr_err("XML Parser Warning: size is invalid value: %s\n", size);
pr_err("XML Parser Error: file size is missing: '%s'", size_buf);
BAIL_ON_TDNF_ERROR(elementInfo->dwError);
}
elementInfo->ml_ctx->size = strtoi(size_buf);
}
else if(!strcmp(elementInfo->startElement, TAG_NAME_HASH))
{
Expand All @@ -502,9 +506,6 @@ TDNFXmlParseData(
}

cleanup:
if(size != NULL){
TDNF_SAFE_FREE_MEMORY(size);
}
return;
error:
goto cleanup;
Expand All @@ -518,6 +519,7 @@ TDNFXmlParseEndElement(
{
struct MetalinkElementInfo* elementInfo = (struct MetalinkElementInfo*)userData;
elementInfo->endElement = name;
elementInfo->startElement = NULL;

if(elementInfo->dwError != 0)
BAIL_ON_TDNF_ERROR(elementInfo->dwError);
Expand Down
1 change: 1 addition & 0 deletions pytests/repo/setup-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ cat << EOF > ${PUBLISH_PATH}/metalink
<metalink version="3.0" xmlns="http://www.metalinker.org/" type="dynamic" pubdate="Wed, 05 Feb 2020 08:14:56 GMT">
<files>
<file name="repomd.xml">
<size>1234</size>
<verification>
</verification>
<resources maxconnections="1">
Expand Down

0 comments on commit f01d8f2

Please sign in to comment.