Mercurial > vim
comparison src/message.c @ 29902:ab2d83e147ca v9.0.0289
patch 9.0.0289: invalid memory write
Commit: https://github.com/vim/vim/commit/beedd0a266cfe524fe2a851caec8316f2e37885c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 27 21:52:52 2022 +0100
patch 9.0.0289: invalid memory write
Problem: Invalid memory write.
Solution: Do not put NUL in a static string.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 27 Aug 2022 23:00:02 +0200 |
parents | a6721cafbc74 |
children | 2516775e8134 |
comparison
equal
deleted
inserted
replaced
29901:5387c6c0d6c8 | 29902:ab2d83e147ca |
---|---|
2235 * "where" specifies where to put the text. | 2235 * "where" specifies where to put the text. |
2236 */ | 2236 */ |
2237 static void | 2237 static void |
2238 put_msg_win(win_T *wp, int where, char_u *t_s, char_u *end, linenr_T lnum) | 2238 put_msg_win(win_T *wp, int where, char_u *t_s, char_u *end, linenr_T lnum) |
2239 { | 2239 { |
2240 int c = *end; | 2240 char_u *p; |
2241 | 2241 |
2242 *end = NUL; | |
2243 if (where == PUT_BELOW) | 2242 if (where == PUT_BELOW) |
2244 ml_append_buf(wp->w_buffer, lnum, t_s, (colnr_T)0, FALSE); | 2243 { |
2244 if (*end != NUL) | |
2245 { | |
2246 p = vim_strnsave(t_s, end - t_s); | |
2247 if (p == NULL) | |
2248 return; | |
2249 } | |
2250 else | |
2251 p = t_s; | |
2252 ml_append_buf(wp->w_buffer, lnum, p, (colnr_T)0, FALSE); | |
2253 if (p != t_s) | |
2254 vim_free(p); | |
2255 } | |
2245 else | 2256 else |
2246 { | 2257 { |
2247 char_u *newp; | 2258 char_u *newp; |
2248 | 2259 |
2249 curbuf = wp->w_buffer; | 2260 curbuf = wp->w_buffer; |
2250 if (where == PUT_APPEND) | 2261 if (where == PUT_APPEND) |
2262 { | |
2251 newp = concat_str(ml_get(lnum), t_s); | 2263 newp = concat_str(ml_get(lnum), t_s); |
2264 if (newp == NULL) | |
2265 return; | |
2266 if (*end != NUL) | |
2267 newp[STRLEN(ml_get(lnum)) + (end - t_s)] = NUL; | |
2268 } | |
2252 else | 2269 else |
2270 { | |
2253 newp = vim_strnsave(t_s, end - t_s); | 2271 newp = vim_strnsave(t_s, end - t_s); |
2272 if (newp == NULL) | |
2273 return; | |
2274 } | |
2254 ml_replace(lnum, newp, FALSE); | 2275 ml_replace(lnum, newp, FALSE); |
2255 curbuf = curwin->w_buffer; | 2276 curbuf = curwin->w_buffer; |
2256 } | 2277 } |
2257 redraw_win_later(wp, UPD_NOT_VALID); | 2278 redraw_win_later(wp, UPD_NOT_VALID); |
2258 | 2279 |
2259 // set msg_col so that a newline is written if needed | 2280 // set msg_col so that a newline is written if needed |
2260 msg_col = STRLEN(t_s); | 2281 msg_col = STRLEN(t_s); |
2261 | |
2262 *end = c; | |
2263 } | 2282 } |
2264 #endif | 2283 #endif |
2265 | 2284 |
2266 /* | 2285 /* |
2267 * The display part of msg_puts_attr_len(). | 2286 * The display part of msg_puts_attr_len(). |