/*
-** For the states FLD2, BODY2 memory is allocated for f->value.
-** For the states LENERR2, FMTERR2, ERR2 and FILEEOF2 no memory is allocated.
+** For the states FLD2, BODY2 and FMTERR2 memory is allocated for f->value.
+** For the states LENERR2, ERR2 and FILEEOF2 no memory is allocated.
*/
enum state
m_getfld2(enum state s, struct field *f, FILE *msg)
return LENERR2;
}
+ *f->name = '\0';
+ f->namelen = 0;
+
switch (s) {
case FLD2:
if (*(tmpline + nchars - 1) != '\n') {
- free(tmpline);
+ if (f->value) {
+ free(f->value);
+ }
+ f->value = tmpline;
+ f->valuelen = nchars;
+ f->alloclen = len;
return FMTERR2;
}
f->namelen = copyname(f->name, tmpline);
if (f->namelen < 1) {
- free(tmpline);
+ if (f->value) {
+ free(f->value);
+ }
+ f->value = tmpline;
+ f->valuelen = nchars;
+ f->alloclen = len;
return FMTERR2;
}
}
if (*(tmpline + nchars - 1) != '\n') {
- free(tmpline);
+ if (f->value) {
+ free(f->value);
+ }
+ f->value = tmpline;
+ f->valuelen = nchars;
+ f->alloclen = len;
return FMTERR2;
}
return FLD2;
case BODY2:
- *f->name = '\0';
- f->namelen = 0;
if (f->value) {
free(f->value);
}
copyname(char *dst, char *src)
{
size_t len;
- char *sep = strchr(src, ':');
+ char *cp, *sep;
- if (!sep) {
+ if (!(sep = strchr(src, ':'))) {
return 0;
}
+ /* whitespace is forbidden in name */
+ for (cp=src; cp<sep; cp++) {
+ if (isspace(*cp)) {
+ return 0;
+ }
+ }
len = sep - src;
if (len >= NAMESZ) {