raster pushed a commit to branch master.
commit 84bc17eb08437da037b01a087df47e4b0a25365c
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date: Mon Feb 25 12:00:07 2013 +0900
Fix 1byte invalid read & do memset, rewind if needed.
Summary:
1. because eina_simple_xml_parse uses char *, buf should be null
terminated. So I use memset.
2. Because NULL is needed at the end, I add one more byte.
fread read exact bytes and has no NULL.
3. If buf is failed to alloc (very rarely case), it is not need to rewind
and memset.
Test Plan: Use valgrind and elm_map_name_add API
Reviewers: tasn, bluezery
Reviewed By: raster
CC: seoz
Differential Revision: https://phab.enlightenment.org/D10
---
src/lib/elm_map.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/lib/elm_map.c b/src/lib/elm_map.c
index 2788616..28bcc7a 100644
--- a/src/lib/elm_map.c
+++ b/src/lib/elm_map.c
@@ -2800,12 +2800,11 @@ _kml_parse(Elm_Map_Route *r)
sz = ftell(f);
if (sz > 0)
{
- char *buf;
-
- fseek(f, 0, SEEK_SET);
- buf = malloc(sz);
+ char *buf = malloc(sz + 1);
if (buf)
{
+ memset(buf, 0, sz + 1);
+ rewind(f);
if (fread(buf, 1, sz, f))
{
eina_simple_xml_parse
@@ -2891,12 +2890,11 @@ _name_parse(Elm_Map_Name *n)
sz = ftell(f);
if (sz > 0)
{
- char *buf;
-
- fseek(f, 0, SEEK_SET);
- buf = malloc(sz);
+ char *buf = malloc(sz + 1);
if (buf)
{
+ memset(buf, 0, sz + 1);
+ rewind(f);
if (fread(buf, 1, sz, f))
{
eina_simple_xml_parse
@@ -2933,12 +2931,11 @@ _name_list_parse(Elm_Map_Name_List *nl)
sz = ftell(f);
if (sz > 0)
{
- char *buf;
-
- fseek(f, 0, SEEK_SET);
- buf = malloc(sz);
+ char *buf = malloc(sz + 1);
if (buf)
{
+ memset(buf, 0, sz + 1);
+ rewind(f);
if (fread(buf, 1, sz, f))
{
eina_simple_xml_parse
--
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb