Skip to contentSkip to conversation

automount: Fix size arg of fgets(3)

PATCH In review Tomohiro Kusumi 2 participants 2 messages Jul 4, 2016 – Jul 6, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 automount: Fix size arg of fgets(3)

Since fgets(3) reads at most 1 less than size arg, it should probably pass MAX_LINE_LEN+1 given that the conditional in the next line tests if strlen() exceeds MAX_LINE_LEN. (i.e. MAX_LINE_LEN isn't designed to include terminating \0)

buf has MAX_LINE_LEN+2 bytes, so passing MAX_LINE_LEN+1 is ok.

---
 lib/defaults.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/defaults.c +1 -1
index 0e48a78..ae76513 100644
@@ -879,7 +879,7 @@ static int read_config(unsigned int to_syslog, FILE *f, const char *name)
 	char *res;
 
 	new_sec = NULL;
-	while ((res = fgets(buf, MAX_LINE_LEN, f))) {
+	while ((res = fgets(buf, MAX_LINE_LEN + 1, f))) {
 		char *sec, *key, *value;
 
 		if (strlen(res) > MAX_LINE_LEN) {
Signature · 4 lines
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe autofs" in
maintainer
#1 lore raw
Quoted 6 lines · Tomohiro Kusumi

Since fgets(3) reads at most 1 less than size arg, it should probably pass MAX_LINE_LEN+1 given that the conditional in the next line tests if strlen() exceeds MAX_LINE_LEN. (i.e. MAX_LINE_LEN isn't designed to include terminating \0)

buf has MAX_LINE_LEN+2 bytes, so passing MAX_LINE_LEN+1 is ok.

And also added.

Quoted 19 lines
---
 lib/defaults.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/defaults.c +1 -1
index 0e48a78..ae76513 100644
@@ -879,7 +879,7 @@ static int read_config(unsigned int to_syslog, FILE *f,
 const char *name)
 	char *res;
 
 	new_sec = NULL;
-	while ((res = fgets(buf, MAX_LINE_LEN, f))) {
+	while ((res = fgets(buf, MAX_LINE_LEN + 1, f))) {
 		char *sec, *key, *value;
 
Quoted 1 line

if (strlen(res) > MAX_LINE_LEN) {

--
To unsubscribe from this list: send the line "unsubscribe autofs" in