Fix RegEnumValueW returned 234 (#131)
RegEnumValueW may return ERROR_MORE_DATA (234). If lpData is NULL and lpcbData is non-NULL, the function stores the size of the data, in bytes, in the variable pointed to by lpcbData. This enables an application to determine the best way to allocate a buffer for the data. If the buffer specified by lpData is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of lpData are undefined.
This commit is contained in:
parent
9491729542
commit
77cdb7086d
10
session.c
10
session.c
|
@ -343,11 +343,7 @@ static void setup_session_user_vars(Session* s) /* set user environment variable
|
||||||
ret = RegEnumValueW(reg_key, i++, name, &name_chars, 0, &type, (LPBYTE)data, &required);
|
ret = RegEnumValueW(reg_key, i++, name, &name_chars, 0, &type, (LPBYTE)data, &required);
|
||||||
if (ret == ERROR_NO_MORE_ITEMS)
|
if (ret == ERROR_NO_MORE_ITEMS)
|
||||||
break;
|
break;
|
||||||
else if (ret != ERROR_SUCCESS) {
|
else if (ret == ERROR_MORE_DATA || required > data_chars * 2) {
|
||||||
error("Error retrieving user environment variables. RegEnumValueW returned %d", ret);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (required > data_chars * 2) {
|
|
||||||
if (data != NULL)
|
if (data != NULL)
|
||||||
free(data);
|
free(data);
|
||||||
data = xmalloc(required);
|
data = xmalloc(required);
|
||||||
|
@ -355,6 +351,10 @@ static void setup_session_user_vars(Session* s) /* set user environment variable
|
||||||
i--;
|
i--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
else if (ret != ERROR_SUCCESS) {
|
||||||
|
error("Error retrieving user environment variables. RegEnumValueW returned %d", ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == REG_SZ)
|
if (type == REG_SZ)
|
||||||
to_apply = data;
|
to_apply = data;
|
||||||
|
|
Loading…
Reference in New Issue