NOAA-EMC / NCEPLIBS-grib_util

This is a collection of NCEP GRIB related utilities.
Other
21 stars 11 forks source link

length of level and time abbreviation strings are incorrect in degrib2.F90 #224

Closed edwardhartnett closed 1 year ago

edwardhartnett commented 1 year ago

In degrib2.F90 we have:

character(len = 30) :: labbrev character(len = 90) :: tabbrev and:

call prlevel(gfld%ipdtnum, gfld%ipdtmpl, labbrev) call prvtime(gfld%ipdtnum, gfld%ipdtmpl, listsec1, tabbrev)

However, as the documentation of prlevel() says:

!> @param[out] labbrev Character array which gets the string
!> describing the level. Must be of length 40.

And the documentation of prvtime() says:

!> @param[out] tabbrev Character array that will get the date and time
!> string. Must be of length 100.

This is because prlevel() contains this code:

`labbrev(1:40) = " "

And prvtime() contains this code:

` tabbrev(1:100) = " " ``

This causes a memory error when address sanitizer is used, like this:

==16066==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff84e1e2ea at pc 0x7f28d6ea4c33 bp 0x7fff84e1cdd0 sp 0x7fff84e1c578
WRITE of size 99 at 0x7fff84e1e2ea thread T0
    #0 0x7f28d6ea4c32 in __interceptor_memset ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:799
    #1 0x563084ff90db in prvtime_ /home/ed/NCEPLIBS-grib_util/src/degrib2/prvtime.F90:37
    #2 0x563084feed0f in degrib2 /home/ed/NCEPLIBS-grib_util/src/degrib2/degrib2.F90:124
    #3 0x563084ff1373 in main /home/ed/NCEPLIBS-grib_util/src/degrib2/degrib2.F90:15
    #4 0x7f28d66e0082 in __libc_start_main ../csu/libc-start.c:308
    #5 0x563084feb5ed in _start (/home/ed/NCEPLIBS-grib_util/b/src/degrib2/degrib2+0x55ed)