pud: nmealib: fix buffer overrun
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 22 Oct 2012 10:08:32 +0000 (12:08 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 22 Oct 2012 11:55:39 +0000 (13:55 +0200)
Coverity:
CID 739669 (#1 of 1): Out-of-bounds write (OVERRUN)
At (11): Overrunning array of 64 bytes at byte offset 64 by dereferencing
         pointer "psSatInfo".

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/nmealib/src/generate.c

index 1d641aa..4a51b50 100644 (file)
@@ -168,9 +168,9 @@ int nmea_gen_GPGSV(char *s, const int len, const nmeaGPGSV *pack) {
        char sCount[2];
        char sIndex[2];
        char sSatCount[4];
-       char sSatInfo[64];
+       char sSatInfo[(NMEA_SATINPACK * 4) + 1];
        char * psSatInfo = &sSatInfo[0];
-       int ssSatInfo = sizeof(sSatInfo);
+       int ssSatInfo = sizeof(sSatInfo) - 1;
        bool satinview = nmea_INFO_is_present(pack->present, SATINVIEW);
        int i;