29c29
< * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c 154860 2006-01-26 12:19:10Z harti $
---
> * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c 160341 2006-07-14 09:07:56Z harti $
50d49
<
70a70,74
> /* Maximum lengths for the strings according to the MIB */
> #define SWR_NAME_MLEN (64 + 1)
> #define SWR_PATH_MLEN (128 + 1)
> #define SWR_PARAM_MLEN (128 + 1)
>
78,81c82,85
< u_char name[64 + 1];
< struct asn_oid id;
< u_char path[128 + 1];
< u_char parameters[128 + 1];
---
> u_char *name; /* it may be NULL */
> const struct asn_oid *id;
> u_char *path; /* it may be NULL */
> u_char *parameters; /* it may be NULL */
86c90
< #define HR_SWRUN_FOUND 0x001
---
> #define HR_SWRUN_FOUND 0x001
136a141,143
> free(entry->name);
> free(entry->path);
> free(entry->parameters);
155c162
< * Translate the kernel's process status to the SNMP one.
---
> * Translate the kernel's process status to SNMP.
201a209
> size_t pname_len;
203c211,214
< strlcpy((char*)entry->name, kp->ki_comm, sizeof(entry->name));
---
> pname_len = strlen(kp->ki_comm) + 1;
> entry->name = reallocf(entry->name, pname_len);
> if (entry->name != NULL)
> strlcpy(entry->name, kp->ki_comm, pname_len);
205c216
< entry->id = oid_zeroDotZero; /* unknown id - FIXME */
---
> entry->id = &oid_zeroDotZero; /* unknown id - FIXME */
207,209d217
< entry->path[0] = '\0';
< entry->parameters[0] = '\0';
<
212c220
< argv = kvm_getargv(hr_kd, kp, sizeof(entry->parameters) - 1);
---
> argv = kvm_getargv(hr_kd, kp, SWR_PARAM_MLEN - 1);
214c222
< memset(entry->parameters, '\0', sizeof(entry->parameters));
---
> u_char param[SWR_PARAM_MLEN];
215a224,225
> memset(param, '\0', sizeof(param));
>
224,225c234,244
< memset(entry->path, '\0', sizeof(entry->path));
< strlcpy((char*)entry->path, *argv, sizeof(entry->path));
---
> size_t path_len;
>
> path_len = strlen(*argv) + 1;
> if (path_len > SWR_PATH_MLEN)
> path_len = SWR_PATH_MLEN;
>
> entry->path = reallocf(entry->path, path_len);
> if (entry->path != NULL) {
> memset(entry->path, '\0', path_len);
> strlcpy((char*)entry->path, *argv, path_len);
> }
231c250
< if (entry->parameters[0] != 0) {
---
> if (param[0] != 0) {
236,237c255
< strlcat((char *)entry->parameters,
< " ", sizeof(entry->parameters));
---
> strlcat((char *)param, " ", sizeof(param));
239,240c257
< strlcat((char *)entry->parameters, *argv,
< sizeof(entry->parameters));
---
> strlcat((char *)param, *argv, sizeof(param));
242a260,266
> /* reuse pname_len */
> pname_len = strlen(param) + 1;
> if (pname_len > SWR_PARAM_MLEN)
> pname_len = SWR_PARAM_MLEN;
>
> entry->parameters = reallocf(entry->parameters, pname_len);
> strlcpy(entry->parameters, param, pname_len);
263a288
> size_t name_len;
268c293,295
< strlcpy((char *)entry->name, kfs->name, sizeof(entry->name));
---
> name_len = strlen(kfs->name) + 1;
> if (name_len > SWR_NAME_MLEN)
> name_len = SWR_NAME_MLEN;
269a297,300
> entry->name = reallocf(entry->name, name_len);
> if (entry->name != NULL)
> strlcpy((char *)entry->name, kfs->name, name_len);
>
271c302
< entry->path[0] = '\0';
---
> entry->path = NULL;
274c305
< entry->parameters[0] = '\0';
---
> entry->parameters = NULL;
276c307
< entry->id = oid_zeroDotZero; /* unknown id - FIXME */
---
> entry->id = &oid_zeroDotZero; /* unknown id - FIXME */
632,633c663,667
< ret = string_get(value, entry->name, -1);
< break;
---
> if (entry->name != NULL)
> ret = string_get(value, entry->name, -1);
> else
> ret = string_get(value, "", -1);
> break;
636,637c670,672
< value->v.oid = entry->id;
< break;
---
> assert(entry->id != NULL);
> value->v.oid = *entry->id;
> break;
639,641c674,679
< case LEAF_hrSWRunPath:
< ret = string_get(value, entry->path, -1);
< break;
---
> case LEAF_hrSWRunPath:
> if (entry->path != NULL)
> ret = string_get(value, entry->path, -1);
> else
> ret = string_get(value, "", -1);
> break;
644,645c682,686
< ret = string_get(value, entry->parameters, -1);
< break;
---
> if (entry->parameters != NULL)
> ret = string_get(value, entry->parameters, -1);
> else
> ret = string_get(value, "", -1);
> break;
648c689
< value->v.integer = entry->type;
---
> value->v.integer = entry->type;
652c693
< value->v.integer = entry->status;
---
> value->v.integer = entry->status;
656c697
< abort();
---
> abort();
735c776
< abort();
---
> abort();
748c789
< return (SNMP_ERR_NOERROR);
---
> return (SNMP_ERR_NOERROR);
< * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c 154860 2006-01-26 12:19:10Z harti $
---
> * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c 160341 2006-07-14 09:07:56Z harti $
50d49
<
70a70,74
> /* Maximum lengths for the strings according to the MIB */
> #define SWR_NAME_MLEN (64 + 1)
> #define SWR_PATH_MLEN (128 + 1)
> #define SWR_PARAM_MLEN (128 + 1)
>
78,81c82,85
< u_char name[64 + 1];
< struct asn_oid id;
< u_char path[128 + 1];
< u_char parameters[128 + 1];
---
> u_char *name; /* it may be NULL */
> const struct asn_oid *id;
> u_char *path; /* it may be NULL */
> u_char *parameters; /* it may be NULL */
86c90
< #define HR_SWRUN_FOUND 0x001
---
> #define HR_SWRUN_FOUND 0x001
136a141,143
> free(entry->name);
> free(entry->path);
> free(entry->parameters);
155c162
< * Translate the kernel's process status to the SNMP one.
---
> * Translate the kernel's process status to SNMP.
201a209
> size_t pname_len;
203c211,214
< strlcpy((char*)entry->name, kp->ki_comm, sizeof(entry->name));
---
> pname_len = strlen(kp->ki_comm) + 1;
> entry->name = reallocf(entry->name, pname_len);
> if (entry->name != NULL)
> strlcpy(entry->name, kp->ki_comm, pname_len);
205c216
< entry->id = oid_zeroDotZero; /* unknown id - FIXME */
---
> entry->id = &oid_zeroDotZero; /* unknown id - FIXME */
207,209d217
< entry->path[0] = '\0';
< entry->parameters[0] = '\0';
<
212c220
< argv = kvm_getargv(hr_kd, kp, sizeof(entry->parameters) - 1);
---
> argv = kvm_getargv(hr_kd, kp, SWR_PARAM_MLEN - 1);
214c222
< memset(entry->parameters, '\0', sizeof(entry->parameters));
---
> u_char param[SWR_PARAM_MLEN];
215a224,225
> memset(param, '\0', sizeof(param));
>
224,225c234,244
< memset(entry->path, '\0', sizeof(entry->path));
< strlcpy((char*)entry->path, *argv, sizeof(entry->path));
---
> size_t path_len;
>
> path_len = strlen(*argv) + 1;
> if (path_len > SWR_PATH_MLEN)
> path_len = SWR_PATH_MLEN;
>
> entry->path = reallocf(entry->path, path_len);
> if (entry->path != NULL) {
> memset(entry->path, '\0', path_len);
> strlcpy((char*)entry->path, *argv, path_len);
> }
231c250
< if (entry->parameters[0] != 0) {
---
> if (param[0] != 0) {
236,237c255
< strlcat((char *)entry->parameters,
< " ", sizeof(entry->parameters));
---
> strlcat((char *)param, " ", sizeof(param));
239,240c257
< strlcat((char *)entry->parameters, *argv,
< sizeof(entry->parameters));
---
> strlcat((char *)param, *argv, sizeof(param));
242a260,266
> /* reuse pname_len */
> pname_len = strlen(param) + 1;
> if (pname_len > SWR_PARAM_MLEN)
> pname_len = SWR_PARAM_MLEN;
>
> entry->parameters = reallocf(entry->parameters, pname_len);
> strlcpy(entry->parameters, param, pname_len);
263a288
> size_t name_len;
268c293,295
< strlcpy((char *)entry->name, kfs->name, sizeof(entry->name));
---
> name_len = strlen(kfs->name) + 1;
> if (name_len > SWR_NAME_MLEN)
> name_len = SWR_NAME_MLEN;
269a297,300
> entry->name = reallocf(entry->name, name_len);
> if (entry->name != NULL)
> strlcpy((char *)entry->name, kfs->name, name_len);
>
271c302
< entry->path[0] = '\0';
---
> entry->path = NULL;
274c305
< entry->parameters[0] = '\0';
---
> entry->parameters = NULL;
276c307
< entry->id = oid_zeroDotZero; /* unknown id - FIXME */
---
> entry->id = &oid_zeroDotZero; /* unknown id - FIXME */
632,633c663,667
< ret = string_get(value, entry->name, -1);
< break;
---
> if (entry->name != NULL)
> ret = string_get(value, entry->name, -1);
> else
> ret = string_get(value, "", -1);
> break;
636,637c670,672
< value->v.oid = entry->id;
< break;
---
> assert(entry->id != NULL);
> value->v.oid = *entry->id;
> break;
639,641c674,679
< case LEAF_hrSWRunPath:
< ret = string_get(value, entry->path, -1);
< break;
---
> case LEAF_hrSWRunPath:
> if (entry->path != NULL)
> ret = string_get(value, entry->path, -1);
> else
> ret = string_get(value, "", -1);
> break;
644,645c682,686
< ret = string_get(value, entry->parameters, -1);
< break;
---
> if (entry->parameters != NULL)
> ret = string_get(value, entry->parameters, -1);
> else
> ret = string_get(value, "", -1);
> break;
648c689
< value->v.integer = entry->type;
---
> value->v.integer = entry->type;
652c693
< value->v.integer = entry->status;
---
> value->v.integer = entry->status;
656c697
< abort();
---
> abort();
735c776
< abort();
---
> abort();
748c789
< return (SNMP_ERR_NOERROR);
---
> return (SNMP_ERR_NOERROR);