Skip to contentSkip to conversation

path: Fix an integer overflow in l_path_get_mtime

PATCH Applied Andrew Zaborowski 2 participants 2 messages Mar 2, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 path: Fix an integer overflow in l_path_get_mtime

time_t may be 32 bits wide (also signed) so we need to cast timespec.tv_sec to uint64_t before multiplying by 1000000.

---
 ell/path.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ell/path.c +2 -1
index dfede14..df5a703 100644
@@ -162,7 +162,8 @@ LIB_EXPORT uint64_t l_path_get_mtime(const char *path)
 	if (ret < 0)
 		return L_TIME_INVALID;
 
-	return sb.st_mtim.tv_sec * 1000000 + sb.st_mtim.tv_nsec / 1000;
+	return (uint64_t) sb.st_mtim.tv_sec * 1000000 +
+		sb.st_mtim.tv_nsec / 1000;
 }
 
 /**
Signature · 1 line
2.20.1
#1 lore raw

Hi Andrew,

Quoted 6 lines · Andrew Zaborowski

time_t may be 32 bits wide (also signed) so we need to cast timespec.tv_sec to uint64_t before multiplying by 1000000.

---
  ell/path.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis