epp: fix memory corruption when using #warning and #error 36/96836/2
authorJean Guyomarc'h <jean@guyomarch.bzh>
Wed, 5 Oct 2016 10:00:38 +0000 (12:00 +0200)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 20 Jan 2017 03:27:35 +0000 (19:27 -0800)
The epp instructions #warning and #error would led to a segmentation
fault (invalid free) because the malloced buffer's base pointer was
moved.

@fix

Signed-off-by: Pankaj Mittal <m.pankaj@samsung.com>
Change-Id: I694688fedd6249c0ae34df31ebb8f9670aed847e

src/bin/edje/epp/cpplib.c

index b8e0ff2d64be2fa09b567472e5241901ba719cbd..7351f043b9a95c2c56d7854a67dd6f2d7704c328 100644 (file)
@@ -3904,11 +3904,12 @@ do_error(cpp_reader * pfile, struct directive *keyword EINA_UNUSED,
 {
    int                 length = limit - buf;
    unsigned char      *copy = (unsigned char *)xmalloc(length + 1);
+   unsigned char      *msg = copy;
 
    memcpy(copy, buf, length);
    copy[length] = 0;
-   SKIP_WHITE_SPACE(copy);
-   cpp_error(pfile, "#error %s", copy);
+   SKIP_WHITE_SPACE(msg);
+   cpp_error(pfile, "#error %s", msg);
    free(copy);
    return 0;
 }
@@ -3925,11 +3926,12 @@ do_warning(cpp_reader * pfile, struct directive *keyword EINA_UNUSED,
 {
    int                 length = limit - buf;
    unsigned char      *copy = (unsigned char *)xmalloc(length + 1);
+   unsigned char      *msg = copy;
 
    memcpy(copy, buf, length);
    copy[length] = 0;
-   SKIP_WHITE_SPACE(copy);
-   cpp_warning(pfile, "#warning %s", copy);
+   SKIP_WHITE_SPACE(msg);
+   cpp_warning(pfile, "#warning %s", msg);
    free(copy);
    return 0;
 }