From e17c3aa78caaee99d9f46ff72f0ac39ec3a22c2a Mon Sep 17 00:00:00 2001 From: Matt Mascarenhas Date: Wed, 3 Aug 2022 22:56:24 +0100 Subject: [PATCH] cinera.c: Handle overlong "output" attribute --- cinera/cinera.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cinera/cinera.c b/cinera/cinera.c index 1102e6e..0fe55dc 100644 --- a/cinera/cinera.c +++ b/cinera/cinera.c @@ -23,7 +23,7 @@ typedef struct version CINERA_APP_VERSION = { .Major = 0, .Minor = 10, - .Patch = 8 + .Patch = 9 }; #include // NOTE(matt): varargs @@ -10259,12 +10259,6 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF CollationBuffers->VODPlatform = VODPlatform; } - buffer URLPlayer = {}; - ClaimBuffer(&URLPlayer, BID_URL_PLAYER, MAX_BASE_URL_LENGTH + 1 + MAX_RELATIVE_PAGE_LOCATION_LENGTH + 1 + MAX_BASE_FILENAME_LENGTH); - ConstructPlayerURL(&URLPlayer, N->Project, HMML.metadata.output ? Wrap0(HMML.metadata.output) : BaseFilename); - CopyString(CollationBuffers->URLPlayer, sizeof(CollationBuffers->URLPlayer), "%s", URLPlayer.Location); - DeclaimBuffer(&URLPlayer); - medium *DefaultMedium = CurrentProject->DefaultMedium; if(HMML.metadata.medium) { @@ -10301,6 +10295,21 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF ClearCopyStringNoFormat(N->WorkingThis.Number, sizeof(N->WorkingThis.Number), Wrap0(HMML.metadata.number)); } + string OutputLocation = {}; + if(!HMML.metadata.output) + { + OutputLocation = BaseFilename; + } + else if(StringLength(HMML.metadata.output) > sizeof(N->WorkingThis.OutputLocation)) + { + IndexingErrorSizing(&FilepathL, 0, "output", Wrap0(HMML.metadata.output), MAX_ENTRY_OUTPUT_LENGTH); + Result = RC_ERROR_HMML; + } + else + { + OutputLocation = Wrap0(HMML.metadata.output); + } + string ProjectTitle = BestTitleForHTML(CurrentProject); // TODO(matt): Handle the art and art_variants once .hmml supports them @@ -10352,18 +10361,14 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF if(Result == RC_SUCCESS) { - string OutputLocation = {}; - if(HMML.metadata.output) - { - OutputLocation = Wrap0(HMML.metadata.output); - } - else - { - OutputLocation = BaseFilename; - } - ClearCopyStringNoFormat(N->WorkingThis.OutputLocation, sizeof(N->WorkingThis.OutputLocation), OutputLocation); + buffer URLPlayer = {}; + ClaimBuffer(&URLPlayer, BID_URL_PLAYER, MAX_BASE_URL_LENGTH + SLASH + MAX_RELATIVE_PAGE_LOCATION_LENGTH + SLASH + sizeof(N->WorkingThis.OutputLocation)); + ConstructPlayerURL(&URLPlayer, N->Project, Wrap0i(N->WorkingThis.OutputLocation, sizeof(N->WorkingThis.OutputLocation))); + CopyString(CollationBuffers->URLPlayer, sizeof(CollationBuffers->URLPlayer), "%s", URLPlayer.Location); + DeclaimBuffer(&URLPlayer); + if(N->This) { string OldOutputLocation = Wrap0i(N->This->OutputLocation, sizeof(N->This->OutputLocation));