From 855675741b415b75e301bcb7bd757b3845b1c62c Mon Sep 17 00:00:00 2001 From: Shamser Ahmed Date: Mon, 18 Mar 2024 10:46:33 +0000 Subject: [PATCH] HPCC-31416 CDistributedSuperFile::querySubFile may return incorrect subfile When sub==true and idx is not found, it should throw an exception. Without this change, the code function did not always throw but dropped through to return an incorrect subfile. This incorrect behaviour has the effect of masking bugs in the code and causing random crashes. The fix is to ensure an exception is thrown when sub==true and idx is not found. Signed-off-by: Shamser Ahmed --- dali/base/dadfs.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dali/base/dadfs.cpp b/dali/base/dadfs.cpp index 43f13ac2291..51100ed8a6f 100644 --- a/dali/base/dadfs.cpp +++ b/dali/base/dadfs.cpp @@ -6274,10 +6274,12 @@ class CDistributedSuperFile: public CDistributedFileBase if (sub) { unsigned subfilen = idx; - ForEachItemIn(i,subfiles) { + ForEachItemIn(i,subfiles) + { IDistributedFile &f=subfiles.item(i); IDistributedSuperFile *super = f.querySuperFile(); - if (super) { + if (super) + { unsigned ns = super->numSubFiles(true); if (ns>subfilen) return super->querySubFile(subfilen,true); @@ -6288,7 +6290,8 @@ class CDistributedSuperFile: public CDistributedFileBase } throw makeStringExceptionV(-1,"CDistributedSuperFile::querySubFile(%u) for superfile %s - subfile doesn't exist ", idx, logicalName.get()); } - return subfiles.item(idx); + else + return subfiles.item(idx); } virtual IDistributedFile *querySubFileNamed(const char *name, bool sub) override