Skip to content

Commit

Permalink
lib/vector: fix potential buffer overflow (OSGeo#4149)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamDesai authored Aug 8, 2024
1 parent fa781d7 commit c132d68
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/vector/diglib/frmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <grass/vector.h>
#include <grass/glocale.h>
#include <grass/gis.h>

/*!
\brief Read external vector format file
Expand All @@ -34,6 +35,7 @@ int dig_read_frmt_ascii(FILE *dascii, struct Format_info *finfo)
char buff[2001], buf1[2001];
char *ptr;
int frmt = -1;
size_t len;

G_debug(3, "dig_read_frmt_ascii()");

Expand All @@ -46,7 +48,11 @@ int dig_read_frmt_ascii(FILE *dascii, struct Format_info *finfo)
return -1;
}

strcpy(buf1, buff);
len = G_strlcpy(buf1, buff, sizeof(buf1));
if (len >= sizeof(buf1)) {
G_warning(_("Line <%s> is too long"), buff);
return -1;
}
buf1[ptr - buff] = '\0';

ptr++; /* Search for the start of text */
Expand Down Expand Up @@ -98,7 +104,11 @@ int dig_read_frmt_ascii(FILE *dascii, struct Format_info *finfo)
continue;
}

strcpy(buf1, buff);
len = G_strlcpy(buf1, buff, sizeof(buf1));
if (len >= sizeof(buf1)) {
G_warning(_("Line <%s> is too long"), buff);
return -1;
}
buf1[ptr - buff] = '\0';

ptr++; /* Search for the start of text */
Expand Down

0 comments on commit c132d68

Please sign in to comment.