xundump: Clean up lazy coding limiting string length to 65536
Can't just replace the literal 65536 by INT_MAX, because my system's vfprintf() rejects that with EOVERFLOW. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
55857c7b20
commit
a06cea24c1
1 changed files with 13 additions and 7 deletions
|
@ -52,6 +52,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -774,7 +775,7 @@ static int
|
||||||
setstr(int fldno, char *str)
|
setstr(int fldno, char *str)
|
||||||
{
|
{
|
||||||
struct castr *ca;
|
struct castr *ca;
|
||||||
int must_match, idx;
|
int must_match, mismatch, idx;
|
||||||
size_t sz, len;
|
size_t sz, len;
|
||||||
char *memb_ptr, *old;
|
char *memb_ptr, *old;
|
||||||
|
|
||||||
|
@ -789,14 +790,17 @@ setstr(int fldno, char *str)
|
||||||
memb_ptr = cur_obj;
|
memb_ptr = cur_obj;
|
||||||
memb_ptr += ca->ca_off;
|
memb_ptr += ca->ca_off;
|
||||||
must_match = fldval_must_match(fldno);
|
must_match = fldval_must_match(fldno);
|
||||||
|
mismatch = 0;
|
||||||
|
|
||||||
switch (ca->ca_type) {
|
switch (ca->ca_type) {
|
||||||
case NSC_STRING:
|
case NSC_STRING:
|
||||||
old = ((char **)memb_ptr)[idx];
|
old = ((char **)memb_ptr)[idx];
|
||||||
if (!must_match)
|
if (must_match)
|
||||||
|
mismatch = old ? !str || strcmp(old, str) : !!str;
|
||||||
|
else
|
||||||
/* FIXME may leak old value */
|
/* FIXME may leak old value */
|
||||||
((char **)memb_ptr)[idx] = str ? strdup(str) : NULL;
|
((char **)memb_ptr)[idx] = str ? strdup(str) : NULL;
|
||||||
len = 65535; /* really SIZE_MAX, but that's C99 */
|
len = -1; /* unlimited */
|
||||||
break;
|
break;
|
||||||
case NSC_STRINGY:
|
case NSC_STRINGY:
|
||||||
if (CANT_HAPPEN(idx))
|
if (CANT_HAPPEN(idx))
|
||||||
|
@ -810,18 +814,20 @@ setstr(int fldno, char *str)
|
||||||
return gripe("Field %d takes at most %d characters",
|
return gripe("Field %d takes at most %d characters",
|
||||||
fldno + 1, (int)len);
|
fldno + 1, (int)len);
|
||||||
old = memb_ptr;
|
old = memb_ptr;
|
||||||
if (!must_match)
|
if (must_match)
|
||||||
|
mismatch = !str || strncmp(old, str, len);
|
||||||
|
else
|
||||||
strncpy(memb_ptr, str, sz);
|
strncpy(memb_ptr, str, sz);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return gripe("Field %d doesn't take strings", fldno + 1);
|
return gripe("Field %d doesn't take strings", fldno + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (must_match) {
|
if (mismatch) {
|
||||||
if (old && (!str || strncmp(old, str, len)))
|
if (old)
|
||||||
return gripe("Value for field %d must be \"%.*s\"",
|
return gripe("Value for field %d must be \"%.*s\"",
|
||||||
fldno + 1, (int)len, old);
|
fldno + 1, (int)len, old);
|
||||||
if (!old && str)
|
else
|
||||||
return gripe("Value for field %d must be nil", fldno + 1);
|
return gripe("Value for field %d must be nil", fldno + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue