conky-1.10.6-new_graph-oor.patch 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. From 2600d01373ce04b34f698f3887e90a35c77bda61 Mon Sep 17 00:00:00 2001
  2. From: labath <pavelo@centrum.sk>
  3. Date: Tue, 31 Jan 2017 01:31:09 +0000
  4. Subject: [PATCH] Fix an out-of-range error in new_graph (#356)
  5. The code was multiplying the index with the size of the element, and
  6. then adding it to the typed pointer (resulting in a double
  7. multiplication and an OOB access).
  8. Replace the buggy code with a slightly safer c++ alternative.
  9. ---
  10. src/specials.cc | 6 ++----
  11. 1 file changed, 2 insertions(+), 4 deletions(-)
  12. diff --git a/src/specials.cc b/src/specials.cc
  13. index ee941eb..73bd2a2 100644
  14. --- a/src/specials.cc
  15. +++ b/src/specials.cc
  16. @@ -519,14 +519,12 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size, double val)
  17. DBGP("reallocing graph from %d to %d", s->graph_allocated, s->graph_width);
  18. if (!s->graph) {
  19. /* initialize */
  20. - memset(graph, 0, s->graph_width * sizeof(double));
  21. + std::fill_n(graph, s->graph_width, 0.0);
  22. s->scale = 100;
  23. } else {
  24. if (s->graph_width > s->graph_allocated) {
  25. /* initialize the new region */
  26. - memset(graph + (s->graph_allocated * sizeof(double)), 0,
  27. - (s->graph_width - s->graph_allocated) *
  28. - sizeof(double));
  29. + std::fill(graph + s->graph_allocated, graph + s->graph_width, 0.0);
  30. }
  31. }
  32. s->graph = graph;