/var/lib/pcp/testsuite/src/pdubufbounds.c is in pcp-testsuite 4.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | /*
* Copyright (c) 2015 Red Hat
*/
#include <pcp/pmapi.h>
#include "libpcp.h"
#include <assert.h>
#include <math.h>
#include "localconfig.h"
/* Test pdubuf bounds checking logic. */
#define INT sizeof(int)
#define INTALIGN(p) ((void*) ((unsigned long)(p) & (~ (INT-1))))
int main ()
{
size_t sizes[] = { /* nothing smaller than ... */ INT, 16-INT, 15, 16, 400, 1024 };
unsigned num_sizes = sizeof(sizes)/sizeof(sizes[0]);
unsigned i;
/* Allocate individual pdubufs of given size; probe a few bytes above and beyond. */
for (i = 0; i<num_sizes; i++) {
unsigned size = sizes[i]; /* NB: measured in bytes, not ints */
char *buf;
printf("pdubuf size %u\n", size);
buf = (void*) __pmFindPDUBuf(size); /* NB: cast for bytewise rather than intwise arithmetic */
assert (buf != NULL);
__pmPinPDUBuf(buf); /* new pincnt = 2 */
__pmFindPDUBuf(-1); /* report */
#define REPORT_UNPIN(ptr) do { \
char *_p = ptr; \
int _rc = __pmUnpinPDUBuf (_p); \
printf ("unpin (%p) -> %d\n", _p, _rc); \
} while (0);
REPORT_UNPIN(buf - INT*2); /* previous int; rc=0 */
REPORT_UNPIN(INTALIGN(buf+size+INT)); /* second next beyond aligned int; rc=0 */
REPORT_UNPIN(INTALIGN(buf+size+1)); /* next beyond aligned int; rc=0 */
REPORT_UNPIN(INTALIGN(buf+size-1)); /* last int; rc=1 */
REPORT_UNPIN(buf); /* first int; rc=1 */
REPORT_UNPIN(buf); /* first int again; rc=0 */
__pmFindPDUBuf(-1); /* report */
}
return 0;
}
|