Skip to content

Commit 5f6e58e

Browse files
committed
Fix potential buffer overrun.
1 parent 9f9b6f1 commit 5f6e58e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pagemap2.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void parse_maps(const char *maps_file, const char *pagemap_file) {
6666
if(buffer[x] == '\n') x ++;
6767
size_t beginning = x;
6868

69-
while(buffer[x] != '-' && x < sizeof buffer) {
69+
while(buffer[x] != '-' && x+1 < sizeof buffer) {
7070
char c = buffer[x ++];
7171
low *= 16;
7272
if(c >= '0' && c <= '9') {
@@ -78,10 +78,10 @@ void parse_maps(const char *maps_file, const char *pagemap_file) {
7878
else break;
7979
}
8080

81-
while(buffer[x] != '-' && x < sizeof buffer) x ++;
81+
while(buffer[x] != '-' && x+1 < sizeof buffer) x ++;
8282
if(buffer[x] == '-') x ++;
8383

84-
while(buffer[x] != ' ' && x < sizeof buffer) {
84+
while(buffer[x] != ' ' && x+1 < sizeof buffer) {
8585
char c = buffer[x ++];
8686
high *= 16;
8787
if(c >= '0' && c <= '9') {
@@ -97,12 +97,12 @@ void parse_maps(const char *maps_file, const char *pagemap_file) {
9797
#ifdef FIND_LIB_NAME
9898
for(int field = 0; field < 4; field ++) {
9999
x ++; // skip space
100-
while(buffer[x] != ' ' && x < sizeof buffer) x ++;
100+
while(buffer[x] != ' ' && x+1 < sizeof buffer) x ++;
101101
}
102-
while(buffer[x] == ' ' && x < sizeof buffer) x ++;
102+
while(buffer[x] == ' ' && x+1 < sizeof buffer) x ++;
103103

104104
size_t y = x;
105-
while(buffer[y] != '\n' && y < sizeof buffer) y ++;
105+
while(buffer[y] != '\n' && y+1 < sizeof buffer) y ++;
106106
buffer[y] = 0;
107107

108108
lib_name = buffer + x;

0 commit comments

Comments
 (0)