Changeset 11 for trunk/src/sh_tools.c
- Timestamp:
- Jan 2, 2006, 12:03:25 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_tools.c
r1 r11 78 78 #endif 79 79 80 #define SH_REAL_SET 81 80 82 #include "samhain.h" 81 83 #include "sh_mem.h" … … 121 123 char * sh_tools_safe_name (const char * instr, int flag) 122 124 { 125 static char ctest = ~('\\'|'&'|'='|'\''); 123 126 unsigned char c; 124 127 const char * p; 125 128 char tmp[4]; 126 129 char * outstr; 127 int len ;130 int len = 1; 128 131 int i = 0; 129 132 unsigned char val_octal = '\0'; … … 133 136 if (instr) 134 137 len = (3 * strlen(instr)) + 4; 135 else136 len = 1;137 138 138 139 outstr = SH_ALLOC(len); … … 143 144 p = instr; 144 145 145 while (p && *p) 146 #if !defined(SH_USE_XML) 147 (void) flag; /* fix compiler warning */ 148 #endif 149 150 if (!p) 151 goto end; 152 153 while (*p) 146 154 { 147 155 c = *p; … … 154 162 155 163 #ifdef SH_USE_XML 156 if (flag == 1 && (*p) == '"') 157 { 158 sprintf(&outstr[i], "=%02x", c); i+=3; ++p; /* known to fit */ 159 continue; 160 } 161 else if (flag == 1 && (*p) == '&') 162 { 163 sprintf(&outstr[i], "=%02x", c); i+=3; ++p; /* known to fit */ 164 continue; 165 } 166 else if (flag == 1 && (*p) == '<') 167 { /* left angle */ 168 sprintf(&outstr[i], "=%02x", c); i+=3; ++p; /* known to fit */ 169 continue; 170 } 171 else if (flag == 1 && (*p) == '>') 172 { /* right angle */ 173 sprintf(&outstr[i], "=%02x", c); i+=3; ++p; /* known to fit */ 174 continue; 164 if (flag == 1) 165 { 166 if ((*p) == '"') 167 { 168 sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit */ 169 continue; 170 } 171 else if ((*p) == '&') 172 { 173 sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit */ 174 continue; 175 } 176 else if ((*p) == '<') 177 { /* left angle */ 178 sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit */ 179 continue; 180 } 181 else if ((*p) == '>') 182 { /* right angle */ 183 sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit */ 184 continue; 185 } 175 186 } 176 #else 177 (void) flag; /* fix compiler warning */ 178 #endif 179 180 if ( (*p) != '\\' && (*p) != '&' && (*p) != '=' && (*p) != '\'') 187 #endif 188 189 /* if ( (*p) != '\\' && (*p) != '&' && (*p) != '=' && (*p) != '\'') */ 190 if (((*p) & ctest) != 0) 181 191 { 192 outstr[i] = *p; ++i; 193 ++p; 194 182 195 if (c < 31 || c > 126) 183 196 { 184 sprintf(&outstr[i], "=%02x", c); i+=3; ++p;/* known to fit */ 197 --i; 198 sprintf(&outstr[i], "=%02x", c); /* known to fit */ 185 199 } 186 else 187 { 188 outstr[i] = *p; 189 ++i; ++p; 190 } 200 191 201 continue; 192 202 } … … 272 282 } 273 283 } 274 else /* *p == '&' */284 else if (*p == '&') 275 285 { 276 286 ++p; … … 303 313 outstr[i] = '&'; ++i; 304 314 } 305 } 315 } 316 else 317 { 318 outstr[i] = *p; ++i; 319 ++p; 320 } 306 321 } /* while (p && *p) */ 322 323 end: 307 324 308 325 outstr[i] = '\0';
Note:
See TracChangeset
for help on using the changeset viewer.