PERFORCE change 90078 for review
Robert Watson
rwatson at FreeBSD.org
Sat Jan 21 13:55:46 GMT 2006
http://perforce.freebsd.org/chv.cgi?CH=90078
Change 90078 by rwatson at rwatson_sesame on 2006/01/21 13:55:02
Replicate avoidance of hand-coded token sizes in the kernel bsm
token generation code.
Submitted by: phk
Found with: FlexeLint
Affected files ...
.. //depot/projects/trustedbsd/audit3/sys/security/audit/audit_bsm_token.c#4 edit
Differences ...
==== //depot/projects/trustedbsd/audit3/sys/security/audit/audit_bsm_token.c#4 (text+ko) ====
@@ -79,9 +79,10 @@
u_int16_t textlen;
textlen = strlen(text);
- GET_TOKEN_AREA(t, dptr, 9 + textlen);
+ textlen += 1;
- textlen += 1;
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 2 * sizeof(u_char) +
+ sizeof(u_int32_t) + sizeof(u_int16_t) + textlen);
ADD_U_CHAR(dptr, AUT_ARG32);
ADD_U_CHAR(dptr, n);
@@ -101,9 +102,10 @@
u_int16_t textlen;
textlen = strlen(text);
- GET_TOKEN_AREA(t, dptr, 13 + textlen);
+ textlen += 1;
- textlen += 1;
+ GET_TOKEN_AREA(t, dptr, 2 * sizeof(u_char) + sizeof(u_int64_t) +
+ sizeof(u_int16_t) + textlen);
ADD_U_CHAR(dptr, AUT_ARG64);
ADD_U_CHAR(dptr, n);
@@ -140,7 +142,8 @@
u_int16_t pad0_16 = 0;
u_int16_t pad0_32 = 0;
- GET_TOKEN_AREA(t, dptr, 29);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 2 * sizeof(u_int16_t) +
+ 3 * sizeof(u_int32_t) + sizeof(u_int64_t) + sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_ATTR32);
@@ -223,7 +226,7 @@
totdata = datasize * unit_count;
- GET_TOKEN_AREA(t, dptr, totdata + 4);
+ GET_TOKEN_AREA(t, dptr, totdata + 4 * sizeof(u_char));
ADD_U_CHAR(dptr, AUT_DATA);
ADD_U_CHAR(dptr, unit_print);
@@ -246,7 +249,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 9);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 2 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_EXIT);
ADD_U_INT32(dptr, err);
@@ -276,7 +279,8 @@
u_char *dptr = NULL;
int i;
- GET_TOKEN_AREA(t, dptr, n * 4 + 3);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int16_t) +
+ n * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_NEWGROUPS);
ADD_U_INT16(dptr, n);
@@ -296,7 +300,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 5);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_IN_ADDR);
ADD_U_INT32(dptr, internet_addr->s_addr);
@@ -316,7 +320,7 @@
u_char *dptr = NULL;
u_int32_t type = AF_INET6;
- GET_TOKEN_AREA(t, dptr, 21);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 5 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_IN_ADDR_EX);
ADD_U_INT32(dptr, type);
@@ -338,7 +342,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 21);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(struct ip));
ADD_U_CHAR(dptr, AUT_IP);
/*
@@ -360,7 +364,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 6);
+ GET_TOKEN_AREA(t, dptr, 2 * sizeof(u_char) + sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_IPC);
ADD_U_CHAR(dptr, type);
@@ -386,7 +390,7 @@
u_char *dptr = NULL;
u_int16_t pad0 = 0;
- GET_TOKEN_AREA(t, dptr, 29);
+ GET_TOKEN_AREA(t, dptr, 12 * sizeof(u_int16_t) + sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_IPC_PERM);
@@ -417,7 +421,6 @@
return (t);
}
-
/*
* token ID 1 byte
* port IP address 2 bytes
@@ -428,7 +431,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 3);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int16_t));
ADD_U_CHAR(dptr, AUT_IPORT);
ADD_U_INT16(dptr, iport);
@@ -436,7 +439,6 @@
return (t);
}
-
/*
* token ID 1 byte
* size 2 bytes
@@ -448,7 +450,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, bytes + 3);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int16_t) + bytes);
ADD_U_CHAR(dptr, AUT_OPAQUE);
ADD_U_INT16(dptr, bytes);
@@ -485,9 +487,11 @@
/* XXXRW: else ...? */
filelen = strlen(file);
- GET_TOKEN_AREA(t, dptr, filelen + 12);
+ filelen += 1;
+
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 2 * sizeof(u_int32_t) +
+ sizeof(u_int16_t) + filelen);
- filelen += 1;
timems = tm.tv_usec/1000;
ADD_U_CHAR(dptr, AUT_OTHER_FILE32);
@@ -512,9 +516,9 @@
u_int16_t textlen;
textlen = strlen(text);
- GET_TOKEN_AREA(t, dptr, textlen + 4);
+ textlen += 1;
- textlen += 1;
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int16_t) + textlen);
ADD_U_CHAR(dptr, AUT_TEXT);
ADD_U_INT16(dptr, textlen);
@@ -536,9 +540,9 @@
u_int16_t textlen;
textlen = strlen(text);
- GET_TOKEN_AREA(t, dptr, textlen + 4);
+ textlen += 1;
- textlen += 1;
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int16_t) + textlen);
ADD_U_CHAR(dptr, AUT_PATH);
ADD_U_INT16(dptr, textlen);
@@ -567,7 +571,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 37);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 9 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_PROCESS32);
ADD_U_INT32(dptr, auid);
@@ -621,7 +625,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 53);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 13 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_PROCESS32_EX);
ADD_U_INT32(dptr, auid);
@@ -669,7 +673,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 6);
+ GET_TOKEN_AREA(t, dptr, 2 * sizeof(u_char) + sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_RETURN32);
ADD_U_CHAR(dptr, status);
@@ -684,7 +688,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 10);
+ GET_TOKEN_AREA(t, dptr, 2 * sizeof(u_char) + sizeof(u_int64_t));
ADD_U_CHAR(dptr, AUT_RETURN64);
ADD_U_CHAR(dptr, status);
@@ -710,7 +714,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 5);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_SEQ);
ADD_U_INT32(dptr, audit_count);
@@ -745,7 +749,8 @@
u_char *dptr;
u_int16_t so_type;
- GET_TOKEN_AREA(t, dptr, 15);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 2 * sizeof(u_int16_t) +
+ sizeof(u_int32_t) + sizeof(u_int16_t) + sizeof(u_int32_t));
ADD_U_CHAR(dptr, AU_SOCK_TOKEN);
/* Coerce the socket type into a short value */
@@ -797,13 +802,13 @@
token_t *t;
u_char *dptr;
- GET_TOKEN_AREA(t, dptr, 107);
+ GET_TOKEN_AREA(t, dptr, 3 * sizeof(u_char) + strlen(so->sun_path) + 1);
ADD_U_CHAR(dptr, AU_SOCK_UNIX_TOKEN);
/* BSM token has two bytes for family */
ADD_U_CHAR(dptr, 0);
ADD_U_CHAR(dptr, so->sun_family);
- ADD_STRING(dptr, so->sun_path, strlen(so->sun_path));
+ ADD_STRING(dptr, so->sun_path, strlen(so->sun_path) + 1);
return (t);
}
@@ -820,7 +825,8 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 9);
+ GET_TOKEN_AREA(t, dptr, 3 * sizeof(u_char) + sizeof(u_int16_t) +
+ sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_SOCKINET32);
/*
@@ -842,7 +848,8 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 21);
+ GET_TOKEN_AREA(t, dptr, 3 * sizeof(u_char) + sizeof(u_int16_t) +
+ 4 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_SOCKINET128);
/*
@@ -889,7 +896,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 37);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 9 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_SUBJECT32);
ADD_U_INT32(dptr, auid);
@@ -943,7 +950,7 @@
token_t *t;
u_char *dptr = NULL;
- GET_TOKEN_AREA(t, dptr, 53);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 13 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_SUBJECT32_EX);
ADD_U_INT32(dptr, auid);
@@ -1023,7 +1030,8 @@
nextarg = *(args + count);
}
- GET_TOKEN_AREA(t, dptr, 5 + totlen);
+ totlen += count * sizeof(char); /* nul terminations. */
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int32_t) + totlen);
ADD_U_CHAR(dptr, AUT_EXEC_ARGS);
ADD_U_INT32(dptr, count);
@@ -1061,7 +1069,8 @@
nextenv = *(env + count);
}
- GET_TOKEN_AREA(t, dptr, 5 + totlen);
+ totlen += sizeof(char) * count;
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int32_t) + totlen);
ADD_U_CHAR(dptr, AUT_EXEC_ENV);
ADD_U_INT32(dptr, count);
@@ -1103,7 +1112,8 @@
#endif
/* XXXRW: else ...? */
- GET_TOKEN_AREA(t, dptr, 18);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int32_t) +
+ sizeof(u_char) + 2 * sizeof(u_int16_t) + 2 * sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_HEADER32);
ADD_U_INT32(dptr, rec_size);
@@ -1154,7 +1164,8 @@
u_char *dptr = NULL;
u_int16_t magic = TRAILER_PAD_MAGIC;
- GET_TOKEN_AREA(t, dptr, 7);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int16_t) +
+ sizeof(u_int32_t));
ADD_U_CHAR(dptr, AUT_TRAILER);
ADD_U_INT16(dptr, magic);
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list