Fix potential heap buffer overflow in hdfs.c. Contributed by Igor Chervatyuk.

(cherry picked from commit 4972e7a246)
This commit is contained in:
Akira Ajisaka 2021-07-22 10:31:32 +09:00
parent b98a8d259b
commit 78c5fdd90d
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
1 changed files with 6 additions and 1 deletions

View File

@ -945,9 +945,14 @@ struct hdfsStreamBuilder {
struct hdfsStreamBuilder *hdfsStreamBuilderAlloc(hdfsFS fs,
const char *path, int flags)
{
int path_len = strlen(path);
size_t path_len = strlen(path);
struct hdfsStreamBuilder *bld;
// Check for overflow in path_len
if (path_len > SIZE_MAX - sizeof(struct hdfsStreamBuilder)) {
errno = EOVERFLOW;
return NULL;
}
// sizeof(hdfsStreamBuilder->path) includes one byte for the string
// terminator
bld = malloc(sizeof(struct hdfsStreamBuilder) + path_len);