pmap: Always check the return value of fgets().
Otherwise "the contents of the array remain unchanged and a null pointer is returned" or "the array contents are indeterminate and a null pointer is returned".
This commit is contained in:
parent
6f82fa2b04
commit
0d9d0a5206
12
pmap.c
12
pmap.c
@ -328,6 +328,8 @@ static void print_extended_maps (FILE *f)
|
|||||||
c = mapbuf[strlen(mapbuf) - 1];
|
c = mapbuf[strlen(mapbuf) - 1];
|
||||||
while (c != '\n') {
|
while (c != '\n') {
|
||||||
ret = fgets(mapbuf, sizeof mapbuf, f);
|
ret = fgets(mapbuf, sizeof mapbuf, f);
|
||||||
|
if (!ret || !mapbuf[0])
|
||||||
|
xerrx(EXIT_FAILURE, _("Unknown format in smaps file!"));
|
||||||
c = mapbuf[strlen(mapbuf) - 1];
|
c = mapbuf[strlen(mapbuf) - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,8 +341,8 @@ static void print_extended_maps (FILE *f)
|
|||||||
if (strlen(inode ) > maxw5) maxw5 = strlen(inode);
|
if (strlen(inode ) > maxw5) maxw5 = strlen(inode);
|
||||||
|
|
||||||
ret = fgets(mapbuf, sizeof mapbuf, f);
|
ret = fgets(mapbuf, sizeof mapbuf, f);
|
||||||
nfields = sscanf(mapbuf, "%"DETL"[^:]: %"NUML"[0-9] kB %c",
|
nfields = ret ? sscanf(mapbuf, "%"DETL"[^:]: %"NUML"[0-9] kB %c",
|
||||||
detail_desc, value_str, &c);
|
detail_desc, value_str, &c) : 0;
|
||||||
listnode = listhead;
|
listnode = listhead;
|
||||||
/* === READ MAPPING DETAILS === */
|
/* === READ MAPPING DETAILS === */
|
||||||
while (ret != NULL && nfields == 2) {
|
while (ret != NULL && nfields == 2) {
|
||||||
@ -382,12 +384,12 @@ static void print_extended_maps (FILE *f)
|
|||||||
listnode = listnode->next;
|
listnode = listnode->next;
|
||||||
loop_end:
|
loop_end:
|
||||||
ret = fgets(mapbuf, sizeof mapbuf, f);
|
ret = fgets(mapbuf, sizeof mapbuf, f);
|
||||||
nfields = sscanf(mapbuf, "%"DETL"[^:]: %"NUML"[0-9] kB %c",
|
nfields = ret ? sscanf(mapbuf, "%"DETL"[^:]: %"NUML"[0-9] kB %c",
|
||||||
detail_desc, value_str, &c);
|
detail_desc, value_str, &c) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === GET VMFLAGS === */
|
/* === GET VMFLAGS === */
|
||||||
nfields = sscanf(mapbuf, "VmFlags: %[a-z ]", vmflags);
|
nfields = ret ? sscanf(mapbuf, "VmFlags: %[a-z ]", vmflags) : 0;
|
||||||
if (nfields == 1) {
|
if (nfields == 1) {
|
||||||
if (! has_vmflags) has_vmflags = 1;
|
if (! has_vmflags) has_vmflags = 1;
|
||||||
ret = fgets(mapbuf, sizeof mapbuf, f);
|
ret = fgets(mapbuf, sizeof mapbuf, f);
|
||||||
|
Loading…
Reference in New Issue
Block a user