* fhandler_registry.cc (DEFAULT_VALUE_NAME): Remove constant.

(encode_regname): Encode empty (default) name to "@".
	Encode "@" to "%40".  Change error return to -1.
	(decode_regname): Decode "@" to empty name.  Decode "%40" to "@".
	(fhandler_registry::exists): Skip check for keys if name is empty.
	Remove check for DEFAULT_VALUE_NAME, now handled by decode_regname ().
	(fhandler_registry::readdir): Remove check for empty name, now
	handled by encode_regname ().
	(fhandler_registry::open): Remove check for DEFAULT_VALUE_NAME.
	(fhandler_registry::open_key): Fail with ENOENT if key name is empty.
This commit is contained in:
Corinna Vinschen 2008-12-16 09:20:05 +00:00
parent 1348f65bb9
commit 2cc8b9e014
2 changed files with 82 additions and 68 deletions

View File

@ -1,3 +1,16 @@
2008-12-16 Christian Franke <franke@computer.org>
* fhandler_registry.cc (DEFAULT_VALUE_NAME): Remove constant.
(encode_regname): Encode empty (default) name to "@".
Encode "@" to "%40". Change error return to -1.
(decode_regname): Decode "@" to empty name. Decode "%40" to "@".
(fhandler_registry::exists): Skip check for keys if name is empty.
Remove check for DEFAULT_VALUE_NAME, now handled by decode_regname ().
(fhandler_registry::readdir): Remove check for empty name, now
handled by encode_regname ().
(fhandler_registry::open): Remove check for DEFAULT_VALUE_NAME.
(fhandler_registry::open_key): Fail with ENOENT if key name is empty.
2008-12-15 Corinna Vinschen <corinna@vinschen.de> 2008-12-15 Corinna Vinschen <corinna@vinschen.de>
* syscalls.cc (gen_full_path_at): Use isabspath instead of isdirsep * syscalls.cc (gen_full_path_at): Use isabspath instead of isdirsep

View File

@ -75,9 +75,6 @@ static const char *special_dot_files[] =
static const int SPECIAL_DOT_FILE_COUNT = static const int SPECIAL_DOT_FILE_COUNT =
(sizeof (special_dot_files) / sizeof (const char *)) - 1; (sizeof (special_dot_files) / sizeof (const char *)) - 1;
/* Name given to default values */
static const char *DEFAULT_VALUE_NAME = "@";
static HKEY open_key (const char *name, REGSAM access, DWORD wow64, bool isValue); static HKEY open_key (const char *name, REGSAM access, DWORD wow64, bool isValue);
/* Return true if char must be encoded. /* Return true if char must be encoded.
@ -89,19 +86,24 @@ must_encode (char c)
} }
/* Encode special chars in registry key or value name. /* Encode special chars in registry key or value name.
* Returns 0: success, -1: error.
*/ */
static int static int
encode_regname (char * dst, const char * src, bool add_val) encode_regname (char * dst, const char * src, bool add_val)
{ {
int di = 0; int di = 0;
if (!src[0])
dst[di++] = '@'; // Default value.
else
for (int si = 0; src[si]; si++) for (int si = 0; src[si]; si++)
{ {
char c = src[si]; char c = src[si];
if (must_encode (c) || if (must_encode (c) ||
(c == '.' && si == 0 && (!src[1] || (src[1] == '.' && !src[2])))) (si == 0 && ((c == '.' && (!src[1] || (src[1] == '.' && !src[2]))) ||
(c == '@' && !src[1]))))
{ {
if (di + 3 >= NAME_MAX + 1) if (di + 3 >= NAME_MAX + 1)
return ENAMETOOLONG; return -1;
__small_sprintf (dst + di, "%%%02x", c); __small_sprintf (dst + di, "%%%02x", c);
di += 3; di += 3;
} }
@ -112,7 +114,7 @@ encode_regname (char * dst, const char * src, bool add_val)
if (add_val) if (add_val)
{ {
if (di + 4 >= NAME_MAX + 1) if (di + 4 >= NAME_MAX + 1)
return ENAMETOOLONG; return -1;
memcpy (dst + di, "%val", 4); memcpy (dst + di, "%val", 4);
di += 4; di += 4;
} }
@ -129,25 +131,31 @@ decode_regname (char * dst, const char * src, int len = -1)
{ {
if (len < 0) if (len < 0)
len = strlen (src); len = strlen (src);
int res = 0; int res = 0;
if (len > 4 && !memcmp (src + len - 4, "%val", 4))
{
len -= 4;
res = 1;
}
int di = 0; int di = 0;
if (len == 1 && src[0] == '@')
; // Default value.
else
for (int si = 0; si < len; si++) for (int si = 0; si < len; si++)
{ {
char c = src[si]; char c = src[si];
if (c == '%') if (c == '%')
{ {
if (si + 4 == len && !memcmp (src + si, "%val", 4))
{
res = 1;
break;
}
if (si + 2 >= len) if (si + 2 >= len)
return -1; return -1;
char s[] = {src[si+1], src[si+2], '\0'}; char s[] = {src[si+1], src[si+2], '\0'};
char *p; char *p;
c = strtoul (s, &p, 16); c = strtoul (s, &p, 16);
if (!(must_encode (c) || if (!(must_encode (c) ||
(c == '.' && si == 0 && (len == 3 || (src[3] == '.' && len == 4))))) (si == 0 && ((c == '.' && (len == 3 || (src[3] == '.' && len == 4))) ||
(c == '@' && len == 3)))))
return -1; return -1;
dst[di++] = c; dst[di++] = c;
si += 2; si += 2;
@ -155,6 +163,7 @@ decode_regname (char * dst, const char * src, int len = -1)
else else
dst[di++] = c; dst[di++] = c;
} }
dst[di] = 0; dst[di] = 0;
return res; return res;
} }
@ -264,7 +273,7 @@ fhandler_registry::exists ()
if (hKey == (HKEY) INVALID_HANDLE_VALUE) if (hKey == (HKEY) INVALID_HANDLE_VALUE)
return 0; return 0;
if (!val_only) if (!val_only && dec_file[0])
{ {
while (ERROR_SUCCESS == while (ERROR_SUCCESS ==
(error = RegEnumKeyEx (hKey, index++, buf, &buf_size, (error = RegEnumKeyEx (hKey, index++, buf, &buf_size,
@ -292,8 +301,7 @@ fhandler_registry::exists ()
NULL, NULL)) NULL, NULL))
|| (error == ERROR_MORE_DATA)) || (error == ERROR_MORE_DATA))
{ {
if ( (buf[0] == '\0' && strcasematch (file, DEFAULT_VALUE_NAME)) if (strcasematch (buf, dec_file))
|| strcasematch (buf, dec_file))
{ {
file_type = -1; file_type = -1;
goto out; goto out;
@ -501,9 +509,6 @@ retry:
if (dir->__d_position & REG_ENUM_VALUES_MASK) if (dir->__d_position & REG_ENUM_VALUES_MASK)
dir->__d_position += 0x10000; dir->__d_position += 0x10000;
if (*buf == 0)
strcpy (de->d_name, DEFAULT_VALUE_NAME);
else
{ {
/* Append "%val" if value name is identical to a previous key name. */ /* Append "%val" if value name is identical to a previous key name. */
unsigned h = hash_path_name (1, buf); unsigned h = hash_path_name (1, buf);
@ -695,10 +700,6 @@ fhandler_registry::open (int flags, mode_t mode)
flags |= O_DIROPEN; flags |= O_DIROPEN;
set_io_handle (handle); set_io_handle (handle);
if (strcasematch (dec_file, DEFAULT_VALUE_NAME))
value_name = cstrdup ("");
else
value_name = cstrdup (dec_file); value_name = cstrdup (dec_file);
if (!(flags & O_DIROPEN) && !fill_filebuf ()) if (!(flags & O_DIROPEN) && !fill_filebuf ())
@ -852,7 +853,7 @@ open_key (const char *name, REGSAM access, DWORD wow64, bool isValue)
if (*name == 0 && isValue == true) if (*name == 0 && isValue == true)
goto out; goto out;
if (val_only) if (val_only || !component[0])
{ {
set_errno (ENOENT); set_errno (ENOENT);
if (parentOpened) if (parentOpened)