Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | From 24ce8f62e042e69497e1299212504c356179e15b Mon Sep 17 00:00:00 2001 |
| 2 | From: Lee Duncan <lduncan@suse.com> |
| 3 | Date: Tue, 6 Nov 2018 11:16:06 -0800 |
| 4 | Subject: [PATCH] Fix i586 build issues with string length overflow. |
| 5 | |
| 6 | Gcc7 warns of possible string print overflow, on i586, |
| 7 | when printing password length (via a macro), generating |
| 8 | errors like: |
| 9 | |
| 10 | [ 59s] ^~~~~~~~~~~~~~~~~~~~ |
| 11 | [ 59s] In file included from /usr/include/stdio.h:862:0, |
| 12 | [ 59s] from idbm.h:27, |
| 13 | [ 59s] from context.h:22, |
| 14 | [ 59s] from idbm.c:59: |
| 15 | [ 59s] /usr/include/bits/stdio2.h:64:10: note: |
| 16 | '__builtin___snprintf_chk' output between 2 and 11 bytes into a |
| 17 | destination of size 8 |
| 18 | [ 59s] return __builtin___snprintf_chk (__s, __n, |
| 19 | __USE_FORTIFY_LEVEL - 1, |
| 20 | [ 59s] ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | ~~~~~~~~~~ |
| 22 | [ 59s] __bos (__s), __fmt, __va_arg_pack ()); |
| 23 | [ 59s] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | [ 59s] cc1: all warnings being treated as errors |
| 25 | [ 59s] make[1]: *** [<builtin>: idbm.o] Error 1 |
| 26 | [ 59s] make[1]: Leaving directory |
| 27 | |
| 28 | The fix is to limit the size of the string printed, so that no |
| 29 | overflow is possible. |
| 30 | |
| 31 | The print macros in usr/idbm.c were updated, as well, to match |
| 32 | the newer version in libopeniscsiusr/idbm.c, also to help the |
| 33 | i586 build. |
| 34 | |
| 35 | Upstream-Status: Backport[https://github.com/open-iscsi/open-iscsi/commit/24ce8f62e042e69497e1299212504c356179e15b] |
| 36 | |
| 37 | Signed-off-by: Mingli Yu <mingli.yu@windriver.com> |
| 38 | --- |
| 39 | libopeniscsiusr/idbm.c | 2 +- |
| 40 | usr/idbm.c | 11 ++++++----- |
| 41 | 2 files changed, 7 insertions(+), 6 deletions(-) |
| 42 | |
| 43 | diff --git a/libopeniscsiusr/idbm.c b/libopeniscsiusr/idbm.c |
| 44 | index 7724de2..055dd9a 100644 |
| 45 | --- a/libopeniscsiusr/idbm.c |
| 46 | +++ b/libopeniscsiusr/idbm.c |
| 47 | @@ -676,7 +676,7 @@ updated: |
| 48 | if (!passwd_done && !strcmp(#_param, name)) { \ |
| 49 | passwd_done = 1; \ |
| 50 | name = #_param "_length"; \ |
| 51 | - snprintf(passwd_len, 8, "%d", (int)strlen(value)); \ |
| 52 | + snprintf(passwd_len, 8, "%.7d", (int)strlen(value) & 0xffff); \ |
| 53 | value = passwd_len; \ |
| 54 | goto setup_passwd_len; \ |
| 55 | } |
| 56 | diff --git a/usr/idbm.c b/usr/idbm.c |
| 57 | index a0207e2..89a6c27 100644 |
| 58 | --- a/usr/idbm.c |
| 59 | +++ b/usr/idbm.c |
| 60 | @@ -30,6 +30,7 @@ |
| 61 | #include <fcntl.h> |
| 62 | #include <sys/stat.h> |
| 63 | #include <sys/file.h> |
| 64 | +#include <inttypes.h> |
| 65 | |
| 66 | #include "idbm.h" |
| 67 | #include "idbm_fields.h" |
| 68 | @@ -65,7 +66,7 @@ static struct idbm *db; |
| 69 | #define __recinfo_int(_key, _info, _rec, _name, _show, _n, _mod) do { \ |
| 70 | _info[_n].type = TYPE_INT; \ |
| 71 | strlcpy(_info[_n].name, _key, NAME_MAXVAL); \ |
| 72 | - snprintf(_info[_n].value, VALUE_MAXVAL, "%d", _rec->_name); \ |
| 73 | + snprintf(_info[_n].value, VALUE_MAXVAL, "%" PRIi32, _rec->_name); \ |
| 74 | _info[_n].data = &_rec->_name; \ |
| 75 | _info[_n].data_len = sizeof(_rec->_name); \ |
| 76 | _info[_n].visible = _show; \ |
| 77 | @@ -76,7 +77,7 @@ static struct idbm *db; |
| 78 | #define __recinfo_uint8(_key, _info, _rec, _name, _show, _n, _mod) do { \ |
| 79 | _info[_n].type = TYPE_UINT8; \ |
| 80 | strlcpy(_info[_n].name, _key, NAME_MAXVAL); \ |
| 81 | - snprintf(_info[_n].value, VALUE_MAXVAL, "%d", _rec->_name); \ |
| 82 | + snprintf(_info[_n].value, VALUE_MAXVAL, "%" PRIu8, _rec->_name); \ |
| 83 | _info[_n].data = &_rec->_name; \ |
| 84 | _info[_n].data_len = sizeof(_rec->_name); \ |
| 85 | _info[_n].visible = _show; \ |
| 86 | @@ -87,7 +88,7 @@ static struct idbm *db; |
| 87 | #define __recinfo_uint16(_key, _info, _rec, _name, _show, _n, _mod) do { \ |
| 88 | _info[_n].type = TYPE_UINT16; \ |
| 89 | strlcpy(_info[_n].name, _key, NAME_MAXVAL); \ |
| 90 | - snprintf(_info[_n].value, VALUE_MAXVAL, "%d", _rec->_name); \ |
| 91 | + snprintf(_info[_n].value, VALUE_MAXVAL, "%" PRIu16, _rec->_name); \ |
| 92 | _info[_n].data = &_rec->_name; \ |
| 93 | _info[_n].data_len = sizeof(_rec->_name); \ |
| 94 | _info[_n].visible = _show; \ |
| 95 | @@ -98,7 +99,7 @@ static struct idbm *db; |
| 96 | #define __recinfo_uint32(_key, _info, _rec, _name, _show, _n, _mod) do { \ |
| 97 | _info[_n].type = TYPE_UINT32; \ |
| 98 | strlcpy(_info[_n].name, _key, NAME_MAXVAL); \ |
| 99 | - snprintf(_info[_n].value, VALUE_MAXVAL, "%d", _rec->_name); \ |
| 100 | + snprintf(_info[_n].value, VALUE_MAXVAL, "%" PRIu32, _rec->_name); \ |
| 101 | _info[_n].data = &_rec->_name; \ |
| 102 | _info[_n].data_len = sizeof(_rec->_name); \ |
| 103 | _info[_n].visible = _show; \ |
| 104 | @@ -1041,7 +1042,7 @@ updated: |
| 105 | if (!passwd_done && !strcmp(#_param, name)) { \ |
| 106 | passwd_done = 1; \ |
| 107 | name = #_param "_length"; \ |
| 108 | - snprintf(passwd_len, 8, "%d", (int)strlen(value)); \ |
| 109 | + snprintf(passwd_len, 8, "%.7" PRIi32, (int)strlen(value) & 0xffff); \ |
| 110 | value = passwd_len; \ |
| 111 | goto setup_passwd_len; \ |
| 112 | } |
| 113 | -- |
| 114 | 2.7.4 |
| 115 | |