[Spice-devel] [vdagent-win PATCH] log: avoid crash on failure in log_version

Frediano Ziglio fziglio at redhat.com
Mon Jul 24 11:19:45 UTC 2017


> 
> On Sun, Jul 23, 2017 at 10:37:05AM +0100, Frediano Ziglio wrote:
> > The "throw" statement alone are used to throw an already existing
> > exception however in log_version they were meant to raise an exception.
> > This would have caused a termination of the program.
> > 
> > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> >  common/vdlog.cpp | 17 +++++++++--------
> >  1 file changed, 9 insertions(+), 8 deletions(-)
> > 
> > diff --git a/common/vdlog.cpp b/common/vdlog.cpp
> > index c983127..0a4c816 100644
> > --- a/common/vdlog.cpp
> > +++ b/common/vdlog.cpp
> > @@ -79,33 +79,34 @@ void VDLog::printf(const char* format, ...)
> >  
> >  void log_version()
> >  {
> > -    DWORD handle;
> > -    TCHAR module_fname[MAX_PATH];
> > +    if (![]() -> bool {
> 
> I don't think a lambda is really useful/required here..
> 

Nothing is required. Is fixing a bug so the code is surely useful.

Counterproposal?

Some really radical can be

void log_version()
{
    vd_printf("%u.%u.%u.%u", RC_PRODUCTVERSION);
}

(adding config.h include)


> Christophe
> 
> > +        DWORD handle;
> > +        TCHAR module_fname[MAX_PATH];
> >  
> > -    try {
> >          if (!GetModuleFileName(NULL, module_fname, MAX_PATH)) {
> > -            throw;
> > +            return false;
> >          }
> >          DWORD version_inf_size = GetFileVersionInfoSize(module_fname,
> >          &handle);
> >          if (version_inf_size == 0) {
> > -            throw;
> > +            return false;
> >          }
> >          std::vector<TCHAR> info_buf(version_inf_size);
> >          if (!GetFileVersionInfo(module_fname, handle, version_inf_size,
> >          &info_buf[0])) {
> > -            throw;
> > +            return false;
> >          }
> >          UINT size;
> >          VS_FIXEDFILEINFO* file_info;
> >          if (!VerQueryValue(&info_buf[0], L"\\", (VOID**)&file_info, &size)
> >          ||
> >                  size < sizeof(VS_FIXEDFILEINFO)) {
> > -            throw;
> > +            return false;
> >          }
> >          vd_printf("%lu.%lu.%lu.%lu",
> >              file_info->dwFileVersionMS >> 16,
> >              file_info->dwFileVersionMS & 0x0ffff,
> >              file_info->dwFileVersionLS >> 16,
> >              file_info->dwFileVersionLS & 0x0ffff);
> > -    } catch (...) {
> > +        return true;
> > +    }()) {
> >          vd_printf("get version info failed");
> >      }
> >  }

Frediano


More information about the Spice-devel mailing list