fixed requesting DWORD with sc_ctx_win32_get_config_value
the length of the value is not determined by strlen()
This commit is contained in:
parent
cd557df54d
commit
9294058d5c
@ -1363,12 +1363,14 @@ sc_card_sm_load(struct sc_card *card, const char *module_path, const char *in_mo
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!module_path || strlen(module_path) == 0) {
|
||||
temp_len = PATH_MAX;
|
||||
temp_len = PATH_MAX-1;
|
||||
rv = sc_ctx_win32_get_config_value(NULL, "SmDir", "Software\\OpenSC Project\\OpenSC",
|
||||
temp_path, &temp_len);
|
||||
if (rv == SC_SUCCESS)
|
||||
if (rv == SC_SUCCESS) {
|
||||
temp_path[temp_len] = '\0';
|
||||
module_path = temp_path;
|
||||
}
|
||||
}
|
||||
expanded_len = PATH_MAX;
|
||||
expanded_len = ExpandEnvironmentStringsA(module_path, expanded_val, expanded_len);
|
||||
if (0 < expanded_len && expanded_len < sizeof expanded_val)
|
||||
|
@ -167,12 +167,9 @@ struct _sc_ctx_options {
|
||||
int
|
||||
sc_ctx_win32_get_config_value(const char *name_env,
|
||||
const char *name_reg, const char *name_key,
|
||||
char *out, size_t *out_len)
|
||||
void *out, size_t *out_len)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char temp[PATH_MAX + 1];
|
||||
char *value = NULL;
|
||||
DWORD temp_len = PATH_MAX;
|
||||
long rc;
|
||||
HKEY hKey;
|
||||
|
||||
@ -180,9 +177,12 @@ sc_ctx_win32_get_config_value(const char *name_env,
|
||||
return SC_ERROR_INVALID_ARGUMENTS;
|
||||
|
||||
if (name_env) {
|
||||
value = getenv(name_env);
|
||||
if (value)
|
||||
goto done;
|
||||
char *value = value = getenv(name_env);
|
||||
if (strlen(value) < *out_len)
|
||||
return SC_ERROR_NOT_ENOUGH_MEMORY;
|
||||
memcpy(out, value, strlen(value));
|
||||
*out_len = strlen(value);
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
if (!name_reg)
|
||||
@ -193,35 +193,25 @@ sc_ctx_win32_get_config_value(const char *name_env,
|
||||
|
||||
rc = RegOpenKeyExA(HKEY_CURRENT_USER, name_key, 0, KEY_QUERY_VALUE, &hKey);
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
temp_len = PATH_MAX;
|
||||
rc = RegQueryValueEx( hKey, name_reg, NULL, NULL, (LPBYTE) temp, &temp_len);
|
||||
if ((rc == ERROR_SUCCESS) && (temp_len < PATH_MAX))
|
||||
value = temp;
|
||||
DWORD len = *out_len;
|
||||
rc = RegQueryValueEx(hKey, name_reg, NULL, NULL, out, &len);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
rc = RegOpenKeyExA( HKEY_LOCAL_MACHINE, name_key, 0, KEY_QUERY_VALUE, &hKey );
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
temp_len = PATH_MAX;
|
||||
rc = RegQueryValueEx( hKey, name_reg, NULL, NULL, (LPBYTE) temp, &temp_len);
|
||||
if ((rc == ERROR_SUCCESS) && (temp_len < PATH_MAX))
|
||||
value = temp;
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (value) {
|
||||
if (strlen(value) >= *out_len)
|
||||
return SC_ERROR_BUFFER_TOO_SMALL;
|
||||
strcpy(out, value);
|
||||
*out_len = strlen(out);
|
||||
*out_len = len;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
memset(out, 0, *out_len);
|
||||
*out_len = 0;
|
||||
rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, name_key, 0, KEY_QUERY_VALUE, &hKey);
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
DWORD len = *out_len;
|
||||
rc = RegQueryValueEx(hKey, name_reg, NULL, NULL, out, &len);
|
||||
RegCloseKey(hKey);
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
*out_len = len;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return SC_ERROR_OBJECT_NOT_FOUND;
|
||||
#else
|
||||
@ -677,13 +667,14 @@ static void process_config_file(sc_context_t *ctx, struct _sc_ctx_options *opts)
|
||||
|
||||
memset(ctx->conf_blocks, 0, sizeof(ctx->conf_blocks));
|
||||
#ifdef _WIN32
|
||||
temp_len = PATH_MAX;
|
||||
temp_len = PATH_MAX-1;
|
||||
r = sc_ctx_win32_get_config_value("OPENSC_CONF", "ConfigFile", "Software\\OpenSC Project\\OpenSC",
|
||||
temp_path, &temp_len);
|
||||
if (r) {
|
||||
sc_log(ctx, "process_config_file doesn't find opensc config file. Please set the registry key.");
|
||||
return;
|
||||
}
|
||||
temp_path[temp_len] = '\0';
|
||||
conf_path = temp_path;
|
||||
#else
|
||||
conf_path = getenv("OPENSC_CONF");
|
||||
|
@ -840,7 +840,7 @@ int sc_ctx_detect_readers(sc_context_t *ctx);
|
||||
*/
|
||||
int sc_ctx_win32_get_config_value(const char *env,
|
||||
const char *reg, const char *key,
|
||||
char *out, size_t *out_size);
|
||||
void *out, size_t *out_size);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the specified sc_reader_t object
|
||||
|
@ -342,11 +342,12 @@ sc_profile_load(struct sc_profile *profile, const char *filename)
|
||||
|
||||
if (!profile_dir) {
|
||||
#ifdef _WIN32
|
||||
temp_len = PATH_MAX;
|
||||
temp_len = PATH_MAX - 1;
|
||||
res = sc_ctx_win32_get_config_value(NULL, "ProfileDir", "Software\\OpenSC Project\\OpenSC",
|
||||
temp_path, &temp_len);
|
||||
if (res)
|
||||
LOG_FUNC_RETURN(ctx, res);
|
||||
temp_path[temp_len] = '\0';
|
||||
profile_dir = temp_path;
|
||||
#else
|
||||
profile_dir = SC_PKCS15_PROFILE_DIRECTORY;
|
||||
|
Loading…
Reference in New Issue
Block a user