瀏覽代碼

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

(cherry picked from commit 4972e7a246f4aab665fd04ce72d1848bc5da9d4e)
Akira Ajisaka 3 年之前
父節點
當前提交
78c5fdd90d
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c

+ 6 - 1
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c

@@ -945,9 +945,14 @@ struct hdfsStreamBuilder {
 struct hdfsStreamBuilder *hdfsStreamBuilderAlloc(hdfsFS fs,
 struct hdfsStreamBuilder *hdfsStreamBuilderAlloc(hdfsFS fs,
                                             const char *path, int flags)
                                             const char *path, int flags)
 {
 {
-    int path_len = strlen(path);
+    size_t path_len = strlen(path);
     struct hdfsStreamBuilder *bld;
     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
     // sizeof(hdfsStreamBuilder->path) includes one byte for the string
     // terminator
     // terminator
     bld = malloc(sizeof(struct hdfsStreamBuilder) + path_len);
     bld = malloc(sizeof(struct hdfsStreamBuilder) + path_len);