~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/binary_log.h

Replace MAX_(DATE|TIME).*_WIDTH defines in definitions.h with real (and correct) static const members to Temporal types.

This fixes the buffer overflow in https://bugs.launchpad.net/drizzle/+bug/373468

It also removes a handwritten snprintf in field/datetime.cc
However... this caused us to have to change Temporal to have a way to not
"convert" the int64_t value (so 20090101 becomes 20090101000000 etc) as it
has already been converted and we just want the Temporal type to do the
to_string conversion.

This still causes a failure in 'metadata' test due to size of timestamp type. I need feedback from Jay on when the usecond code comes into play to know the correct fix for this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++ -*-
 
2
 
 
3
#ifndef BINARY_LOG_H_INCLUDED
 
4
#define BINARY_LOG_H_INCLUDED
 
5
 
 
6
#include <drizzled/message/binary_log.pb.h>
 
7
#include "binlog_encoding.h"
 
8
 
 
9
#include <google/protobuf/io/zero_copy_stream.h>
 
10
 
 
11
#include <iosfwd>
 
12
#include <stdexcept>
 
13
 
 
14
namespace BinaryLog {
 
15
  using namespace google::protobuf;
 
16
  using namespace google::protobuf::io;
 
17
 
 
18
  /**
 
19
     Wrapper class to wrap a protobuf event in a type tag and a length.
 
20
 
 
21
     The type tag is not part of the actual message, but is handled
 
22
     separately since it is needed to decode the events.
 
23
  */
 
24
  class Event {
 
25
  public:
 
26
    enum EventType {
 
27
      UNDEF,
 
28
      START,
 
29
      CHAIN,
 
30
      COMMIT,
 
31
      ROLLBACK,
 
32
      QUERY,
 
33
      COUNT
 
34
    };
 
35
 
 
36
    Event(EventType type, Message *message)
 
37
      : m_type(type), m_message(message)
 
38
    {
 
39
    }
 
40
 
 
41
    Event()
 
42
      : m_type(UNDEF), m_message(0)
 
43
    {
 
44
    }
 
45
 
 
46
    ~Event() {
 
47
      delete m_message;
 
48
    }
 
49
 
 
50
    bool write(CodedOutputStream* out) const;
 
51
    void print(std::ostream& out) const;
 
52
    bool read(CodedInputStream* in);
 
53
 
 
54
  private:
 
55
    EventType m_type;
 
56
    Message *m_message;
 
57
  };
 
58
}
 
59
 
 
60
#endif /* BINARY_LOG_H_INCLUDED */