From 8c84870d83dae5e1b1897c204d596649127acd21 Mon Sep 17 00:00:00 2001 From: Qualys Security Advisory Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] pmap: Fix output format of VmFlags. In the headers, the space was misplaced; for example, "pmap -XX $$" outputs "VmFlagsMapping" (without a space). Use justify_print() instead of printf(). There was also an extra space in the output, because vmflags[] (from the "VmFlags:" line) always ends with a space. Overwriting this last space with a null byte fixes this misalignment. --- pmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pmap.c b/pmap.c index 719f3aa6..075037fc 100644 --- a/pmap.c +++ b/pmap.c @@ -392,9 +392,11 @@ loop_end: /* === GET VMFLAGS === */ nfields = ret ? sscanf(mapbuf, "VmFlags: %"VMFL"[a-z ]", vmflags) : 0; if (nfields == 1) { + int len = strlen(vmflags); + if (len > 0 && vmflags[len-1] == ' ') vmflags[--len] = '\0'; + if (len > maxwv) maxwv = len; if (! has_vmflags) has_vmflags = 1; ret = fgets(mapbuf, sizeof mapbuf, f); - if (strlen(vmflags) > maxwv) maxwv = strlen(vmflags); } if (firstmapping == 2) { /* width measurement stage, do not print anything yet */ @@ -437,7 +439,7 @@ loop_end: justify_print(listnode->description, listnode->max_width, 1); if (has_vmflags && is_enabled("VmFlags")) - printf(" %*s", maxwv, "VmFlags"); + maxwv = justify_print("VmFlags", maxwv, 1); if (is_enabled(nls_Mapping)) justify_print(nls_Mapping, 0, 0);