-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libselinux: Add read_spec_entries function to replace sscanf
Currently sscanf is used with %ms parameters that are not supported on all platforms. The new read_spec_entries function may be used to replace these where required. This patch updates sefcontext_compile, label_file and label_android_property services to use the new function. The file and property services have been tested on Android emulator and the file service on Fedora 21. Signed-off-by: Richard Haines <[email protected]>
- Loading branch information
1 parent
a24fc04
commit af41e2b
Showing
5 changed files
with
119 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* This file contains helper functions for labeling support. | ||
* | ||
* Author : Richard Haines <[email protected]> | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
#include <ctype.h> | ||
#include <string.h> | ||
#include "label_internal.h" | ||
|
||
/* | ||
* The read_spec_entries and read_spec_entry functions may be used to | ||
* replace sscanf to read entries from spec files. The file and | ||
* property services now use these. | ||
*/ | ||
|
||
/* Read an entry from a spec file (e.g. file_contexts) */ | ||
static inline int read_spec_entry(char **entry, char **ptr) | ||
{ | ||
int entry_len = 0; | ||
*entry = NULL; | ||
char *tmp_buf = NULL; | ||
|
||
while (isspace(**ptr) && **ptr != '\0') | ||
(*ptr)++; | ||
|
||
tmp_buf = *ptr; | ||
|
||
while (!isspace(**ptr) && **ptr != '\0') { | ||
(*ptr)++; | ||
entry_len++; | ||
} | ||
|
||
*entry = strndup(tmp_buf, entry_len); | ||
if (!*entry) | ||
return -1; | ||
|
||
return 0; | ||
} | ||
|
||
/* | ||
* line_buf - Buffer containing the spec entries . | ||
* num_args - The number of spec parameter entries to process. | ||
* ... - A 'char **spec_entry' for each parameter. | ||
* returns - The number of items processed. | ||
* | ||
* This function calls read_spec_entry() to do the actual string processing. | ||
*/ | ||
int read_spec_entries(char *line_buf, int num_args, ...) | ||
{ | ||
char **spec_entry, *buf_p; | ||
int len, rc, items; | ||
va_list ap; | ||
|
||
len = strlen(line_buf); | ||
if (line_buf[len - 1] == '\n') | ||
line_buf[len - 1] = '\0'; | ||
|
||
buf_p = line_buf; | ||
while (isspace(*buf_p)) | ||
buf_p++; | ||
|
||
/* Skip comment lines and empty lines. */ | ||
if (*buf_p == '#' || *buf_p == '\0') | ||
return 0; | ||
|
||
/* Process the spec file entries */ | ||
va_start(ap, num_args); | ||
|
||
for (items = 0; items < num_args; items++) { | ||
spec_entry = va_arg(ap, char **); | ||
|
||
if (len - 1 == buf_p - line_buf) { | ||
va_end(ap); | ||
return items; | ||
} | ||
|
||
rc = read_spec_entry(spec_entry, &buf_p); | ||
if (rc < 0) { | ||
va_end(ap); | ||
return rc; | ||
} | ||
} | ||
va_end(ap); | ||
return items; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters