Files
s390-tools/libvmdump/dump.h
Jan Höppner 81f9a67d6f libvmdump: Increase message buffer size
The message buffer of DumpException doesn't account for additional
strings such as strerror(), device nodes, or filenames. Make it a bit
larger to be safe.

This fixes the following GCC8 compile warnings:

In file included from vm_dump.h:62,
                 from vm_dump.cpp:17:
dump.h: In static member function ‘static Dump::DumpType
VMDump::getDumpType(const char*)’:
dump.h:46:16: warning: ‘ (’ directive writing 2 bytes into a region of size
between 1 and 200 [-W format-overflow=]
   sprintf(msg, "%s (%s)", m, strerror(errno));
                ^~~~~~~~~
dump.h:46:10: note: ‘sprintf’ output 4 or more bytes (assuming 203) into a
destination of size 200
   sprintf(msg, "%s (%s)", m, strerror(errno));
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dump.h:46:16: warning: ‘ (’ directive writing 2 bytes into a region of size
between 1 and 200 [-W format-overflow=]
   sprintf(msg, "%s (%s)", m, strerror(errno));
                ^~~~~~~~~
dump.h:46:10: note: ‘sprintf’ output 4 or more bytes (assuming 203) into a
destination of size 200
   sprintf(msg, "%s (%s)", m, strerror(errno));
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dump.h:46:16: warning: ‘ (’ directive writing 2 bytes into a region of size
between 1 and 200 [-W format-overflow=]
   sprintf(msg, "%s (%s)", m, strerror(errno));
                ^~~~~~~~~
dump.h:46:10: note: ‘sprintf’ output 4 or more bytes (assuming 203) into a
destination of size 200
   sprintf(msg, "%s (%s)", m, strerror(errno));
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2018-11-16 15:01:41 +01:00

96 lines
2.0 KiB
C++

/*
* vmdump - z/VM dump conversion library
*
* Dump base class
*
* Copyright IBM Corp. 2004, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef DUMP_H
#define DUMP_H
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
extern int debug;
class DumpException
{
public:
DumpException(void) {
msg[0] = 0;
errorCode = 0;
}
DumpException(const char *m) {
sprintf(msg, "%s", m);
errorCode = 0;
}
const char *what(void) const { return msg; }
int code(void) const { return errorCode; }
protected:
char msg[2048];
int errorCode;
};
class DumpErrnoException : public DumpException
{
public:
DumpErrnoException(const char *m) {
sprintf(msg, "%s (%s)", m, strerror(errno));
errorCode = errno;
}
};
class Dump
{
public:
Dump(const char *filename, const char *mode);
Dump(void) : fh(0) {}
virtual ~Dump(void);
typedef enum {DT_VM32, DT_VM64, DT_VM64_BIG, DT_LKCD32, DT_LKCD64,
DT_UNKNOWN} DumpType;
virtual void readMem(char *buf, int size) = 0;
virtual int seekMem(uint64_t offset) = 0;
virtual uint64_t getMemSize(void) const = 0;
virtual struct timeval getDumpTime(void) const = 0;
protected:
FILE *fh;
};
class ProgressBar
{
public:
ProgressBar(void) { progressPercentage = -1; }
void initProgress(void);
void displayProgress(uint64_t value, uint64_t maxValue);
private:
int progressPercentage;
};
void s390TodToTimeval(uint64_t todval, struct timeval *xtime);
int vm_convert(const char *inputFileName, const char *outputFileName,
const char *progName);
static inline void dump_read(void *ptr, size_t size, size_t nmemb,
FILE *stream)
{
if (fread(ptr, size, nmemb, stream) != nmemb)
throw(DumpErrnoException("fread failed"));
}
static inline void dump_seek(FILE *stream, long offset, int whence)
{
if (fseek(stream, offset, whence) == -1)
throw(DumpErrnoException("fseek failed"));
}
#endif /* DUMP_H */