This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][libiberty] Fix read buffer overflow in split_directories()


In line
  if (dirs[num_dirs - 1] == NULL)
'num_dirs' can be 0.

Regards, Tim

From 65ca7c0688cb823ebde141c7cf74075db7cd0aa0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20R=C3=BChsen?= <tim.ruehsen@gmx.de>
Date: Sun, 10 Nov 2019 00:12:44 +0100
Subject: [PATCH] [libiberty] Fix read buffer overflow in split_directories()

* libiberty/make-relative-prefix.c: Check array index before use
---
 libiberty/make-relative-prefix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c
index ec0b0ee749..d53304eca7 100644
--- a/libiberty/make-relative-prefix.c
+++ b/libiberty/make-relative-prefix.c
@@ -186,7 +186,7 @@ split_directories (const char *name, int *ptr_num_dirs)
     dirs[num_dirs++] = save_string (q, p - 1 - q);
   dirs[num_dirs] = NULL;
 
-  if (dirs[num_dirs - 1] == NULL)
+  if (num_dirs && dirs[num_dirs - 1] == NULL)
     {
       free_split_directories (dirs);
       return NULL;
-- 
2.24.0

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]