Skip to contentSkip to conversation

kbuild: replace unbounded sprintf call in modpost

PATCH In review Kees Cook 2 participants 2 messages Oct 25, 2013 – Nov 7, 2013 Kbuild

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 kbuild: replace unbounded sprintf call in modpost

The modpost tool could overflow its stack buffer if someone was running with an insane shell environment. Regardless, it's technically a bug, so this fixes it to truncate the string instead of seg-faulting.

Found by Coverity.

---
 scripts/mod/sumversion.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mod/sumversion.c +1 -1
index 9dfcd6d988da..deb2994b04c4 100644
@@ -416,7 +416,7 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
 		basename = strrchr(modname, '/') + 1;
 	else
 		basename = modname;
-	sprintf(filelist, "%s/%.*s.mod", modverdir,
+	snprintf(filelist, sizeof(filelist), "%s/%.*s.mod", modverdir,
 		(int) strlen(basename) - 2, basename);
 
 	file = grab_file(filelist, &len);
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 7 lines · Kees Cook

The modpost tool could overflow its stack buffer if someone was running with an insane shell environment. Regardless, it's technically a bug, so this fixes it to truncate the string instead of seg-faulting.

Found by Coverity.

Applied to kbuild.git#kbuild.

Michal