From b3aadc5a258fcf02ebd9ebef83e74ccfe1869184 Mon Sep 17 00:00:00 2001 From: Neal Krawetz Date: Wed, 6 Nov 2024 03:06:50 -0700 Subject: [PATCH] Format: Fixing space indent when there is no signature. Incorporating feedback from Bu11etmagnet related to checking is an unsigned size_t is negative. --- src/format-isobmff.cpp | 2 +- src/format-jpeg.cpp | 2 +- src/format-matroska.cpp | 2 +- src/format-png.cpp | 2 +- src/format-riff.cpp | 2 +- src/seal-parse.cpp | 13 +++++++------ src/sign-verify.cpp | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/format-isobmff.cpp b/src/format-isobmff.cpp index fe1b0e4..74f2b45 100644 --- a/src/format-isobmff.cpp +++ b/src/format-isobmff.cpp @@ -368,7 +368,7 @@ sealfield * Seal_BMFF (sealfield *Args, mmapfile *Mmap) Args = Seal_BMFFsign(Args,Mmap); // Add a signature as needed if (SealGetIindex(Args,"@s",2)==0) // no signatures { - printf("No SEAL signatures found.\n"); + printf(" No SEAL signatures found.\n"); } return(Args); diff --git a/src/format-jpeg.cpp b/src/format-jpeg.cpp index 01a24f5..906a49c 100644 --- a/src/format-jpeg.cpp +++ b/src/format-jpeg.cpp @@ -721,7 +721,7 @@ sealfield * Seal_JPEG (sealfield *Args, mmapfile *Mmap) Args = Seal_JPEGsign(Args,Mmap,FFDAoffset, (PreviousBlockType == 0xffe8) ? 0xffe9 : 0xffe8); if (SealGetIindex(Args,"@s",2)==0) // no signatures { - printf("No SEAL signatures found.\n"); + printf(" No SEAL signatures found.\n"); } return(Args); diff --git a/src/format-matroska.cpp b/src/format-matroska.cpp index 48c4e97..57f1032 100644 --- a/src/format-matroska.cpp +++ b/src/format-matroska.cpp @@ -244,7 +244,7 @@ sealfield * Seal_Matroska (sealfield *Args, mmapfile *Mmap) Args = Seal_Matroskasign(Args,Mmap); // Add a signature as needed if (SealGetIindex(Args,"@s",2)==0) // no signatures { - printf("No SEAL signatures found.\n"); + printf(" No SEAL signatures found.\n"); } return(Args); diff --git a/src/format-png.cpp b/src/format-png.cpp index 4655b32..11ecdb4 100644 --- a/src/format-png.cpp +++ b/src/format-png.cpp @@ -374,7 +374,7 @@ sealfield * Seal_PNG (sealfield *Args, mmapfile *Mmap) Args = Seal_PNGsign(Args,Mmap,IEND_offset); // Add a signature as needed if (SealGetIindex(Args,"@s",2)==0) // no signatures { - printf("No SEAL signatures found.\n"); + printf(" No SEAL signatures found.\n"); } return(Args); diff --git a/src/format-riff.cpp b/src/format-riff.cpp index 3ddba70..9f3e837 100644 --- a/src/format-riff.cpp +++ b/src/format-riff.cpp @@ -271,7 +271,7 @@ sealfield * Seal_RIFF (sealfield *Args, mmapfile *Mmap) Args = Seal_RIFFsign(Args,Mmap); // Add a signature as needed if (SealGetIindex(Args,"@s",2)==0) // no signatures { - printf("No SEAL signatures found.\n"); + printf(" No SEAL signatures found.\n"); } return(Args); diff --git a/src/seal-parse.cpp b/src/seal-parse.cpp index efa2e89..6242f62 100644 --- a/src/seal-parse.cpp +++ b/src/seal-parse.cpp @@ -68,7 +68,7 @@ void SealStrEncode (sealfield *Data) // Count amount of new space required for(i=j=0; i < Data->ValueLen; i++,j++) { - if (strchr("'\"",Data->Value[i])) { j++; } + if (strchr("'\"\\",Data->Value[i])) { j++; } } // i=string length, j=new string length @@ -78,14 +78,15 @@ void SealStrEncode (sealfield *Data) Data->Value = (byte*)realloc(Data->Value,Data->ValueLen+4); memset(Data->Value+i,0,j-i+4); // clear new memory // Now copy over all new characters - i--; j--; // Start at the last character - while((i >= 0) && (j > i)) + // Start at the last character + // NOTE: Can't check if (i >= 0) since size_t is unsigned; always true. + while((i > 0) && (j > i)) { - Data->Value[j] = Data->Value[i]; - if (strchr("'\"",Data->Value[i])) + Data->Value[j-1] = Data->Value[i-1]; + if (strchr("'\"\\",Data->Value[i-1])) { j--; - Data->Value[j]='\\'; + Data->Value[j-1]='\\'; } j--; i--; } diff --git a/src/sign-verify.cpp b/src/sign-verify.cpp index 049f6d1..65797c4 100644 --- a/src/sign-verify.cpp +++ b/src/sign-verify.cpp @@ -657,7 +657,7 @@ sealfield * SealVerify (sealfield *Rec, mmapfile *Mmap) If it's 1, then check if it covers the start of the file. *****/ signum = SealGetIindex(Rec,"@s",2); - if (signum < 1) // should never happen + if (signum < 1) // happens if the seal record is corrupted { printf(" WARNING: Invalid SEAL record count (%ld).\n",signum); return(Rec);