Skip to contentSkip to conversation

check-qdict: Fix possible crash

PATCH Applied Stefan Weil 2 participants 2 messages Jan 21, 2011 – Feb 20, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 check-qdict: Fix possible crash

This warning is reported by cppcheck:

check-qdict.c:270: warning: scanf without field width limits can crash with huge input data

Fix it by limiting the field widths to 127 (both key and value take 127 characters + a terminating '\0' byte).

---
 check-qdict.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
check-qdict.c +2 -1
index 6afce5a..ecc7fd7 100644
@@ -267,8 +267,9 @@ static QString *read_line(FILE *file, char *key)
 {
     char value[128];
 
-    if (fscanf(file, "%s%s", key, value) == EOF)
+    if (fscanf(file, "%127s%127s", key, value) == EOF) {
         return NULL;
+    }
     remove_dots(key);
     return qstring_from_str(value);
 }
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 11 lines · Stefan Weil

This warning is reported by cppcheck:

check-qdict.c:270: warning: scanf without field width limits can crash with huge input data

Fix it by limiting the field widths to 127 (both key and value take 127 characters + a terminating '\0' byte).

---
 check-qdict.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Thanks, applied.

Quoted 20 lines
check-qdict.c +2 -1
index 6afce5a..ecc7fd7 100644
@@ -267,8 +267,9 @@ static QString *read_line(FILE *file, char *key)
 {
     char value[128];
 
-    if (fscanf(file, "%s%s", key, value) == EOF)
+    if (fscanf(file, "%127s%127s", key, value) == EOF) {
         return NULL;
+    }
     remove_dots(key);
     return qstring_from_str(value);
 }
Signature · 1 line
1.7.2.3
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net