2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-29 13:28:19 +00:00

* fix small memory leak in parser_main.c

* fixup instances of my inability to spell separator
  * minor code formatting cleanup in parser_lex.l
This commit is contained in:
Steve Beattie 2009-07-24 11:56:07 +00:00
parent ed86641695
commit da52731c75
4 changed files with 25 additions and 40 deletions

View File

@ -186,7 +186,7 @@ void parse_default_paths(void)
while (fgetline(f, buf, 1024)) { while (fgetline(f, buf, 1024)) {
if (stripcomment(buf) && (t = strstr(buf, "SUBDOMAIN_PATH="))) { if (stripcomment(buf) && (t = strstr(buf, "SUBDOMAIN_PATH="))) {
t += 15; t += 15;
/* handle : seperating path elements */ /* handle : separating path elements */
do { do {
s = strchr(t, ':'); s = strchr(t, ':');
if (s) if (s)

View File

@ -78,13 +78,15 @@ void include_filename(char *filename, int search)
struct stat my_stat; struct stat my_stat;
char *fullpath = NULL; char *fullpath = NULL;
if (search) include_file = search_path(filename, &fullpath); if (search) {
else { include_file = search_path(filename, &fullpath);
} else {
fullpath = strdup(filename); fullpath = strdup(filename);
include_file = fopen(fullpath, "r"); include_file = fopen(fullpath, "r");
} }
if (!include_file) yyerror(_("Could not open '%s'"), fullpath); if (!include_file)
yyerror(_("Could not open '%s'"), fullpath);
if (fstat(fileno(include_file), &my_stat)) if (fstat(fileno(include_file), &my_stat))
yyerror(_("fstat failed for '%s'"), fullpath); yyerror(_("fstat failed for '%s'"), fullpath);
@ -113,8 +115,9 @@ void include_filename(char *filename, int search)
if (dirent->d_name[0] == '.') if (dirent->d_name[0] == '.')
continue; continue;
if (dirent_path) free(dirent_path); if (dirent_path)
if (asprintf(&dirent_path, "%s/%s", fullpath, dirent->d_name)<0) free(dirent_path);
if (asprintf(&dirent_path, "%s/%s", fullpath, dirent->d_name) < 0)
yyerror("Out of memory"); yyerror("Out of memory");
name_len = strlen(dirent->d_name); name_len = strlen(dirent->d_name);
@ -137,10 +140,11 @@ void include_filename(char *filename, int search)
if (!(yyin = fopen(dirent_path,"r"))) if (!(yyin = fopen(dirent_path,"r")))
yyerror(_("Could not open '%s'"), filename); yyerror(_("Could not open '%s'"), filename);
PDEBUG("Opened include \"%s\"\n", filename); PDEBUG("Opened include \"%s\"\n", filename);
yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE )); yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
} }
} }
if (dirent_path) free(dirent_path); if (dirent_path)
free(dirent_path);
closedir(dir); closedir(dir);
} }
} }
@ -153,7 +157,7 @@ CLOSE_BRACE \}
SLASH \/ SLASH \/
COLON : COLON :
END_OF_RULE [,] END_OF_RULE [,]
SEPERATOR {UP} SEPARATOR {UP}
RANGE - RANGE -
MODE_CHARS ([RrWwaLlMmkXx])|(([Uu]|[Pp]|[Cc])[Xx])|(([Pp]|[Cc])?[Ii][Xx]) MODE_CHARS ([RrWwaLlMmkXx])|(([Uu]|[Pp]|[Cc])[Xx])|(([Pp]|[Cc])?[Ii][Xx])
MODES {MODE_CHARS}+ MODES {MODE_CHARS}+
@ -231,7 +235,7 @@ LT_EQUAL <=
* without any spaces in between (because it's * without any spaces in between (because it's
* a longer match). So now, when I want to * a longer match). So now, when I want to
* match any random string, I go into a * match any random string, I go into a
* seperate state. */ * separate state. */
yylval = (YYSTYPE) processunquoted(yytext, yyleng); yylval = (YYSTYPE) processunquoted(yytext, yyleng);
PDEBUG("Found sub name: \"%s\"\n", yylval); PDEBUG("Found sub name: \"%s\"\n", yylval);
BEGIN(INITIAL); BEGIN(INITIAL);
@ -244,7 +248,7 @@ LT_EQUAL <=
* without any spaces in between (because it's * without any spaces in between (because it's
* a longer match). So now, when I want to * a longer match). So now, when I want to
* match any random string, I go into a * match any random string, I go into a
* seperate state. */ * separate state. */
yylval = (YYSTYPE) processquoted(yytext, yyleng); yylval = (YYSTYPE) processquoted(yytext, yyleng);
PDEBUG("Found sub name: \"%s\"\n", yylval); PDEBUG("Found sub name: \"%s\"\n", yylval);
BEGIN(INITIAL); BEGIN(INITIAL);
@ -265,7 +269,7 @@ LT_EQUAL <=
* without any spaces in between (because it's * without any spaces in between (because it's
* a longer match). So now, when I want to * a longer match). So now, when I want to
* match any random string, I go into a * match any random string, I go into a
* seperate state. */ * separate state. */
yylval = (YYSTYPE) processunquoted(yytext, yyleng); yylval = (YYSTYPE) processunquoted(yytext, yyleng);
PDEBUG("Found sub name: \"%s\"\n", yylval); PDEBUG("Found sub name: \"%s\"\n", yylval);
BEGIN(INITIAL); BEGIN(INITIAL);
@ -278,7 +282,7 @@ LT_EQUAL <=
* without any spaces in between (because it's * without any spaces in between (because it's
* a longer match). So now, when I want to * a longer match). So now, when I want to
* match any random string, I go into a * match any random string, I go into a
* seperate state. */ * separate state. */
yylval = (YYSTYPE) processquoted(yytext, yyleng); yylval = (YYSTYPE) processquoted(yytext, yyleng);
PDEBUG("Found sub name: \"%s\"\n", yylval); PDEBUG("Found sub name: \"%s\"\n", yylval);
BEGIN(INITIAL); BEGIN(INITIAL);
@ -384,7 +388,7 @@ LT_EQUAL <=
* without any spaces in between (because it's * without any spaces in between (because it's
* a longer match). So now, when I want to * a longer match). So now, when I want to
* match any random string, I go into a * match any random string, I go into a
* seperate state. */ * separate state. */
yylval = (YYSTYPE) processunquoted(yytext, yyleng); yylval = (YYSTYPE) processunquoted(yytext, yyleng);
PDEBUG("Found sub name: \"%s\"\n", yylval); PDEBUG("Found sub name: \"%s\"\n", yylval);
BEGIN(INITIAL); BEGIN(INITIAL);
@ -397,7 +401,7 @@ LT_EQUAL <=
* without any spaces in between (because it's * without any spaces in between (because it's
* a longer match). So now, when I want to * a longer match). So now, when I want to
* match any random string, I go into a * match any random string, I go into a
* seperate state. */ * separate state. */
yylval = (YYSTYPE) processquoted(yytext, yyleng); yylval = (YYSTYPE) processquoted(yytext, yyleng);
PDEBUG("Found sub name: \"%s\"\n", yylval); PDEBUG("Found sub name: \"%s\"\n", yylval);
BEGIN(INITIAL); BEGIN(INITIAL);
@ -425,8 +429,8 @@ LT_EQUAL <=
{END_OF_RULE} { return TOK_END_OF_RULE; } {END_OF_RULE} { return TOK_END_OF_RULE; }
{SEPERATOR} { {SEPARATOR} {
PDEBUG("Matched a seperator\n"); PDEBUG("Matched a separator\n");
yylval = (YYSTYPE) yytext; yylval = (YYSTYPE) yytext;
BEGIN(SUB_NAME); BEGIN(SUB_NAME);
return TOK_SEP; return TOK_SEP;

View File

@ -427,6 +427,7 @@ static void get_flags_string(void) {
//fprintf(stderr, "flags string: %s\n", flags_string); //fprintf(stderr, "flags string: %s\n", flags_string);
//fprintf(stderr, "changehat %d\n", flag_changehat_version); //fprintf(stderr, "changehat %d\n", flag_changehat_version);
} }
free(flags_string);
return; return;
fail: fail:

View File

@ -86,9 +86,6 @@ SD_EV_PIDFILE=/var/run/sd-event-dispatch.init.pid
SD_STATUS=/usr/sbin/subdomain_status SD_STATUS=/usr/sbin/subdomain_status
SECURITYFS=/sys/kernel/security SECURITYFS=/sys/kernel/security
SUBDOMAINFS_MOUNTPOINT=$(grep subdomainfs /etc/fstab | \
sed -e 's|^[[:space:]]*[^[:space:]]\+[[:space:]]\+\(/[^[:space:]]*\)[[:space:]]\+subdomainfs.*$|\1|' 2> /dev/null)
if [ -d "/var/lib/${MODULE}" ] ; then if [ -d "/var/lib/${MODULE}" ] ; then
APPARMOR_TMPDIR="/var/lib/${MODULE}" APPARMOR_TMPDIR="/var/lib/${MODULE}"
elif [ -d "/var/lib/${OLD_MODULE}" ] ; then elif [ -d "/var/lib/${OLD_MODULE}" ] ; then
@ -103,21 +100,9 @@ STATUS=0
# Test if the apparmor "module" is present. # Test if the apparmor "module" is present.
is_apparmor_present() { is_apparmor_present() {
local modules=$1 local module=$1
shift
while [ $# -gt 0 ] ; do
modules="$modules|$1"
shift
done
# check for subdomainfs version of module
grep -qE "^($modules)[[:space:]]" /proc/modules
if [ $? -ne 0 ] ; then
ls /sys/module/apparmor 2>/dev/null | grep -qE "^($modules)"
fi
test -d "/sys/module/$module"
return $? return $?
} }
@ -256,13 +241,8 @@ is_apparmor_loaded() {
return 0 return 0
fi fi
if [ -f "${SUBDOMAINFS_MOUNTPOINT}/profiles" ]; then
SFS_MOUNTPOINT=${SUBDOMAINFS_MOUNTPOINT}
return 0
fi
# check for subdomainfs version of module # check for subdomainfs version of module
is_apparmor_present apparmor subdomain is_apparmor_present ${MODULE}
return $? return $?
} }