~ubuntu-branches/ubuntu/lucid/mysql-dfsg-5.1/lucid-security

« back to all changes in this revision

Viewing changes to cmd-line-utils/libedit/hist.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 22:33:55 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120222223355-or06x1euyk8n0ldi
Tags: 5.1.61-0ubuntu0.10.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496
* Dropped patches unnecessary with 5.1.61:
  - debian/patches/90_mysql_safer_strmov.dpatch
  - debian/patches/51_ssl_test_certs.dpatch
  - debian/patches/52_CVE-2009-4030.dpatch
  - debian/patches/53_CVE-2009-4484.dpatch
  - debian/patches/54_CVE-2008-7247.dpatch
  - debian/patches/55_CVE-2010-1621.dpatch
  - debian/patches/56_CVE-2010-1850.dpatch
  - debian/patches/57_CVE-2010-1849.dpatch
  - debian/patches/58_CVE-2010-1848.dpatch
  - debian/patches/59_CVE-2010-1626.dpatch
  - debian/patches/60_CVE-2010-2008.dpatch
  - debian/patches/60_CVE-2010-3677.dpatch
  - debian/patches/60_CVE-2010-3678.dpatch
  - debian/patches/60_CVE-2010-3679.dpatch
  - debian/patches/60_CVE-2010-3680.dpatch
  - debian/patches/60_CVE-2010-3681.dpatch
  - debian/patches/60_CVE-2010-3682.dpatch
  - debian/patches/60_CVE-2010-3683.dpatch
  - debian/patches/60_CVE-2010-3833.dpatch
  - debian/patches/60_CVE-2010-3834.dpatch
  - debian/patches/60_CVE-2010-3835.dpatch
  - debian/patches/60_CVE-2010-3836.dpatch
  - debian/patches/60_CVE-2010-3837.dpatch
  - debian/patches/60_CVE-2010-3838.dpatch
  - debian/patches/60_CVE-2010-3839.dpatch
  - debian/patches/60_CVE-2010-3840.dpatch
  - debian/patches/61_disable_longfilename_test.dpatch
  - debian/patches/62_alter_table_fix.dpatch
  - debian/patches/63_cherrypick-upstream-49479.dpatch
  - debian/patches/10_readline_build_fix.dpatch
* debian/mysql-client-5.1.docs: removed EXCEPTIONS-CLIENT file
* debian/mysql-server-5.1.docs,debian/libmysqlclient16.docs,
  debian/libmysqlclient-dev.docs: removed, no longer necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $NetBSD: hist.c,v 1.15 2003/11/01 23:36:39 christos Exp $       */
 
1
/*      $NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $       */
2
2
 
3
3
/*-
4
4
 * Copyright (c) 1992, 1993
55
55
 
56
56
        el->el_history.fun = NULL;
57
57
        el->el_history.ref = NULL;
58
 
        el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
 
58
        el->el_history.buf = el_malloc(EL_BUFSIZ * sizeof(*el->el_history.buf));
59
59
        el->el_history.sz  = EL_BUFSIZ;
60
60
        if (el->el_history.buf == NULL)
61
 
                return (-1);
 
61
                return -1;
62
62
        el->el_history.last = el->el_history.buf;
63
 
        return (0);
 
63
        return 0;
64
64
}
65
65
 
66
66
 
71
71
hist_end(EditLine *el)
72
72
{
73
73
 
74
 
        el_free((ptr_t) el->el_history.buf);
 
74
        el_free(el->el_history.buf);
75
75
        el->el_history.buf = NULL;
76
76
}
77
77
 
80
80
 *      Set new history interface
81
81
 */
82
82
protected int
83
 
hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
 
83
hist_set(EditLine *el, hist_fun_t fun, void *ptr)
84
84
{
85
85
 
86
86
        el->el_history.ref = ptr;
87
87
        el->el_history.fun = fun;
88
 
        return (0);
 
88
        return 0;
89
89
}
90
90
 
91
91
 
96
96
protected el_action_t
97
97
hist_get(EditLine *el)
98
98
{
99
 
        const char *hp;
 
99
        const Char *hp;
100
100
        int h;
101
101
 
102
102
        if (el->el_history.eventno == 0) {      /* if really the current line */
103
 
                (void) strncpy(el->el_line.buffer, el->el_history.buf,
 
103
                (void) Strncpy(el->el_line.buffer, el->el_history.buf,
104
104
                    el->el_history.sz);
105
105
                el->el_line.lastchar = el->el_line.buffer +
106
106
                    (el->el_history.last - el->el_history.buf);
112
112
#endif /* KSHVI */
113
113
                        el->el_line.cursor = el->el_line.lastchar;
114
114
 
115
 
                return (CC_REFRESH);
 
115
                return CC_REFRESH;
116
116
        }
117
117
        if (el->el_history.ref == NULL)
118
 
                return (CC_ERROR);
 
118
                return CC_ERROR;
119
119
 
120
120
        hp = HIST_FIRST(el);
121
121
 
122
122
        if (hp == NULL)
123
 
                return (CC_ERROR);
 
123
                return CC_ERROR;
124
124
 
125
125
        for (h = 1; h < el->el_history.eventno; h++)
126
126
                if ((hp = HIST_NEXT(el)) == NULL) {
127
127
                        el->el_history.eventno = h;
128
 
                        return (CC_ERROR);
 
128
                        return CC_ERROR;
129
129
                }
130
 
        (void) strlcpy(el->el_line.buffer, hp,
 
130
        (void) Strncpy(el->el_line.buffer, hp,
131
131
                        (size_t)(el->el_line.limit - el->el_line.buffer));
132
 
        el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
 
132
        el->el_line.buffer[el->el_line.limit - el->el_line.buffer - 1] = '\0';
 
133
        el->el_line.lastchar = el->el_line.buffer + Strlen(el->el_line.buffer);
133
134
 
134
135
        if (el->el_line.lastchar > el->el_line.buffer
135
136
            && el->el_line.lastchar[-1] == '\n')
144
145
#endif /* KSHVI */
145
146
                el->el_line.cursor = el->el_line.lastchar;
146
147
 
147
 
        return (CC_REFRESH);
 
148
        return CC_REFRESH;
148
149
}
149
150
 
150
151
 
152
153
 *      process a history command
153
154
 */
154
155
protected int
155
 
hist_command(EditLine *el, int argc, const char **argv)
 
156
hist_command(EditLine *el, int argc, const Char **argv)
156
157
{
157
 
        const char *str;
 
158
        const Char *str;
158
159
        int num;
159
 
        HistEvent ev;
 
160
        TYPE(HistEvent) ev;
160
161
 
161
162
        if (el->el_history.ref == NULL)
162
 
                return (-1);
 
163
                return -1;
163
164
 
164
 
        if (argc == 1 || strcmp(argv[1], "list") == 0) {
 
165
        if (argc == 1 || Strcmp(argv[1], STR("list")) == 0) {
165
166
                 /* List history entries */
166
167
 
167
168
                for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
168
169
                        (void) fprintf(el->el_outfile, "%d %s",
169
 
                            el->el_history.ev.num, str);
170
 
                return (0);
 
170
                            el->el_history.ev.num, ct_encode_string(str, &el->el_scratch));
 
171
                return 0;
171
172
        }
172
173
 
173
174
        if (argc != 3)
174
 
                return (-1);
175
 
 
176
 
        num = (int)strtol(argv[2], NULL, 0);
177
 
 
178
 
        if (strcmp(argv[1], "size") == 0)
179
 
                return history(el->el_history.ref, &ev, H_SETSIZE, num);
180
 
 
181
 
        if (strcmp(argv[1], "unique") == 0)
182
 
                return history(el->el_history.ref, &ev, H_SETUNIQUE, num);
 
175
                return -1;
 
176
 
 
177
        num = (int)Strtol(argv[2], NULL, 0);
 
178
 
 
179
        if (Strcmp(argv[1], STR("size")) == 0)
 
180
                return FUNW(history)(el->el_history.ref, &ev, H_SETSIZE, num);
 
181
 
 
182
        if (Strcmp(argv[1], STR("unique")) == 0)
 
183
                return FUNW(history)(el->el_history.ref, &ev, H_SETUNIQUE, num);
183
184
 
184
185
        return -1;
185
186
}
192
193
/*ARGSUSED*/
193
194
hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
194
195
{
195
 
        char *newbuf;
 
196
        Char *newbuf;
196
197
 
197
 
        newbuf = realloc(el->el_history.buf, newsz);
 
198
        newbuf = el_realloc(el->el_history.buf, newsz * sizeof(*newbuf));
198
199
        if (!newbuf)
199
200
                return 0;
200
201
 
201
 
        (void) memset(&newbuf[oldsz], '\0', newsz - oldsz);
 
202
        (void) memset(&newbuf[oldsz], '\0', (newsz - oldsz) * sizeof(*newbuf));
202
203
 
203
204
        el->el_history.last = newbuf +
204
205
                                (el->el_history.last - el->el_history.buf);
207
208
 
208
209
        return 1;
209
210
}
 
211
 
 
212
#ifdef WIDECHAR
 
213
protected wchar_t *
 
214
hist_convert(EditLine *el, int fn, void *arg)
 
215
{
 
216
        HistEventW ev;
 
217
        if ((*(el)->el_history.fun)((el)->el_history.ref, &ev, fn, arg) == -1)
 
218
                return NULL;
 
219
        return ct_decode_string((const char *)(const void *)ev.str,
 
220
            &el->el_scratch);
 
221
}
 
222
#endif