Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#3907 closed defect (fixed)

gbox_to_string: snprintf warning

Reported by: Algunenano Owned by: strk
Priority: low Milestone: PostGIS 2.2.6
Component: liblwgeom Version: master
Keywords: Cc:

Description

GCC 7.2 warning in gbox_to_string:

g_box.c: In function 'gbox_to_string'
g_box.c:421:21: warning: '))' directive output may be truncated writing 2 bytes into a region of size between 0 and 105 [-Wformat-truncation=]
   snprintf(str, sz, "GBOX((%.8g,%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g,%.8g))", gbox->xmin, gbox->ymin, gbox->zmin, gbox->mmin, gbox->xmax, gbox->ymax, gbox->zmax, gbox->mmax);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:862:0,
                 from liblwgeom_internal.h:40,
                 from g_box.c:29:
/usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 26 and 138 bytes into a destination of size 128
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The destination buffer is set too small to handle the max size of the string so it might get truncated.

Github PR: https://github.com/postgis/postgis/pull/165

Change History (4)

comment:1 by pramsey, 7 years ago

In 15996:

Allocate enough space for all possible GBOX string outputs.
From Raúl Marín Algunenano
References #3907

comment:2 by pramsey, 7 years ago

In 15997:

Allocate enough space for all possible GBOX string outputs (Raúl Marín Rodríguez)
References #3907

comment:3 by pramsey, 7 years ago

Resolution: fixed
Status: newclosed

In 15998:

Allocate enough space for all possible GBOX string outputs (Raúl Marín Rodríguez)
Closes #3907

comment:4 by pramsey, 7 years ago

In 15999:

Allocate enough space for all possible GBOX string outputs (Raúl Marín Rodríguez)
References #3907

Note: See TracTickets for help on using tickets.