static int get_all_ids_internal (char *** ids, int * len, db_app_type_t app_type)
{
int ret;
- char* scanf_label_format AUTO_FREE;
FILE* file_db AUTO_FCLOSE;
const char* db_file_name = db_file_names[app_type];
char smack_label[SMACK_LABEL_LEN + 1];
element_t* begin_of_list = NULL;
- if (asprintf(&scanf_label_format, "%%%ds\\n", SMACK_LABEL_LEN) < 0) {
- C_LOGE("Error while creating scanf input label format");
- ret = PC_ERR_MEM_OPERATION;
- goto out;
- }
-
file_db = fopen(db_file_name, "r");
if (NULL == file_db) {
SECURE_SLOGE("Error while opening database file: %s", db_file_name);
// reading from file ("database")
// notice that first element always stays with empty "value"
- while (fscanf(file_db, scanf_label_format, smack_label) == 1) {
+ while (fscanf(file_db, "%" TOSTRING(SMACK_LABEL_LEN) "s\n", smack_label) == 1) {
smack_label[SMACK_LABEL_LEN] = '\0';
if (!smack_label_is_valid(smack_label)) {
C_LOGD("Found entry in database, but it's not correct SMACK label: \"%s\"", smack_label);
{
C_LOGD("Enter function: %s", __func__);
- char* format_string AUTO_FREE;
char smack_subject[SMACK_LABEL_LEN + 1];
char smack_object[SMACK_LABEL_LEN + 1];
- char smack_accesses[10];
+ char smack_accesses[ACC_LEN + 1];
FILE* file AUTO_FCLOSE;
- if (asprintf(&format_string,"%%%ds %%%ds %%%lus\n",
- SMACK_LABEL_LEN, SMACK_LABEL_LEN, (unsigned long)sizeof(smack_accesses)) == -1) {
- C_LOGE("asprintf failed");
- return PC_ERR_MEM_OPERATION;
- }
-
file = fopen(rules_file_path, "r");
C_LOGD("path = %s", rules_file_path);
if (file == NULL) {
return PC_OPERATION_SUCCESS;
}
- while (fscanf(file, format_string, smack_subject, smack_object, smack_accesses) == 3) {
+ while (fscanf(file,
+ "%" TOSTRING(SMACK_LABEL_LEN) "s "
+ "%" TOSTRING(SMACK_LABEL_LEN) "s "
+ "%" TOSTRING(ACC_LEN) "s\n",
+ smack_subject, smack_object, smack_accesses) == 3) {
if (!strcmp(smack_subject, app_label_template))
strcpy(smack_subject, app_label);