#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
+#include <errno.h>
#define LINEBUF 32
#define LINEBUF_MAX 4096
return false;
while (*str) {
- char c = *str;
+ unsigned char c = *str;
if (!isalnum(c) && c != '_') {
if (name || (c < 33) || (c > 126))
return false;
return true;
}
+static inline bool uci_validate_package(const char *str)
+{
+ return uci_validate_str(str, false);
+}
+
+static inline bool uci_validate_type(const char *str)
+{
+ return uci_validate_str(str, false);
+}
+
static inline bool uci_validate_name(const char *str)
{
return uci_validate_str(str, true);
bool uci_validate_text(const char *str)
{
while (*str) {
- if ((*str == '\r') || (*str == '\n') ||
- ((*str < 32) && (*str != '\t')))
+ unsigned char c = *str;
+ if ((c == '\r') || (c == '\n') ||
+ ((c < 32) && (c != '\t')))
return false;
str++;
}
goto error;
lastval:
- if (ptr->package && !uci_validate_str(ptr->package, false))
+ if (ptr->package && !uci_validate_package(ptr->package))
goto error;
if (ptr->section && !uci_validate_name(ptr->section))
ptr->flags |= UCI_LOOKUP_EXTENDED;
if (fd < 0)
goto error;
- if (flock(fd, (write ? LOCK_EX : LOCK_SH)) < 0)
+ ret = flock(fd, (write ? LOCK_EX : LOCK_SH));
+ if ((ret < 0) && (errno != ENOSYS))
goto error;
ret = lseek(fd, 0, pos);
if (!stream)
return;
+ fflush(stream);
fd = fileno(stream);
flock(fd, LOCK_UN);
fclose(stream);