Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/lib/util/substitute.c

    r414 r988  
    2222*/
    2323
    24 #include "includes.h"
     24#include "replace.h"
     25#include "debug.h"
     26#ifndef SAMBA_UTIL_CORE_ONLY
     27#include "charset/charset.h"
     28#else
     29#include "charset_compat.h"
     30#endif
     31#include "substitute.h"
    2532
    2633/**
     
    3037
    3138/**
    32  Substitute a string for a pattern in another string. Make sure there is 
     39 Substitute a string for a pattern in another string. Make sure there is
    3340 enough room!
    3441
    35  This routine looks for pattern in s and replaces it with 
    36  insert. It may do multiple replacements.
     42 This routine looks for pattern in s and replaces it with
     43 insert. It may do multiple replacements or just one.
    3744
    3845 Any of " ; ' $ or ` in the insert string are replaced with _
     
    4148**/
    4249
    43 _PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_t len)
     50static void string_sub2(char *s,const char *pattern, const char *insert, size_t len,
     51                        bool remove_unsafe_characters, bool replace_once,
     52                        bool allow_trailing_dollar)
    4453{
    4554        char *p;
     
    5665                len = ls + 1; /* len is number of *bytes* */
    5766
    58         while (lp <= ls && (p = strstr(s, pattern))) {
     67        while (lp <= ls && (p = strstr_m(s,pattern))) {
    5968                if (ls + (li-lp) >= len) {
    60                         DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n",
     69                        DEBUG(0,("ERROR: string overflow by "
     70                                "%d in string_sub(%.50s, %d)\n",
    6171                                 (int)(ls + (li-lp) - len),
    6272                                 pattern, (int)len));
     
    6878                for (i=0;i<li;i++) {
    6979                        switch (insert[i]) {
     80                        case '$':
     81                                /* allow a trailing $
     82                                 * (as in machine accounts) */
     83                                if (allow_trailing_dollar && (i == li - 1 )) {
     84                                        p[i] = insert[i];
     85                                        break;
     86                                }
    7087                        case '`':
    7188                        case '"':
    7289                        case '\'':
    7390                        case ';':
    74                         case '$':
    7591                        case '%':
    7692                        case '\r':
    7793                        case '\n':
    78                                 p[i] = '_';
    79                                 break;
     94                                if ( remove_unsafe_characters ) {
     95                                        p[i] = '_';
     96                                        /* yes this break should be here
     97                                         * since we want to fall throw if
     98                                         * not replacing unsafe chars */
     99                                        break;
     100                                }
    80101                        default:
    81102                                p[i] = insert[i];
     
    84105                s = p + li;
    85106                ls += (li-lp);
    86         }
     107
     108                if (replace_once)
     109                        break;
     110        }
     111}
     112
     113void string_sub_once(char *s, const char *pattern,
     114                const char *insert, size_t len)
     115{
     116        string_sub2( s, pattern, insert, len, true, true, false );
     117}
     118
     119void string_sub(char *s,const char *pattern, const char *insert, size_t len)
     120{
     121        string_sub2( s, pattern, insert, len, true, false, false );
    87122}
    88123
     
    119154                return NULL;
    120155
    121         SMB_ASSERT(ret[len] == '\0');
     156        if (ret[len] != '\0') {
     157                DEBUG(0,("Internal error at %s(%d): string not terminated\n",
     158                         __FILE__, __LINE__));
     159                abort();
     160        }
    122161
    123162        talloc_set_name_const(ret, ret);
     
    147186        if (!*pattern)
    148187                return;
    149        
     188
    150189        if (len == 0)
    151190                len = ls + 1; /* len is number of *bytes* */
    152        
    153         while (lp <= ls && (p = strstr(s,pattern))) {
     191
     192        while (lp <= ls && (p = strstr_m(s,pattern))) {
    154193                if (ls + (li-lp) >= len) {
    155                         DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n",
     194                        DEBUG(0,("ERROR: string overflow by "
     195                                "%d in all_string_sub(%.50s, %d)\n",
    156196                                 (int)(ls + (li-lp) - len),
    157197                                 pattern, (int)len));
Note: See TracChangeset for help on using the changeset viewer.