netfilter: nf_conntrack_h323: Correct indentation when H323_TRACE defined
Subsystems (3)
PATCH 1/1 netfilter: nf_conntrack_h323: Correct indentation when H323_TRACE defined
From: David Laight <[email protected]>
The trace lines are indented using PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.
Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
--- net/netfilter/nf_conntrack_h323_asn1.c | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-)
net/netfilter/nf_conntrack_h323_asn1.c +19 -19
@@ -276,7 +276,7 @@ static unsigned int get_uint(struct bitstr *bs, int b)static int decode_nul (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);return H323_ERROR_NONE ; }
@@ -284,7 +284,7 @@ static int decode_nul(struct bitstr *bs, const struct field_t *f,static int decode_bool (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);INC_BIT (bs);if (nf_h323_error_boundary (bs,0 ,0 ))
@@ -297,7 +297,7 @@ static int decode_oid(struct bitstr *bs, const struct field_t *f, {int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);BYTE_ALIGN (bs);if (nf_h323_error_boundary (bs,1 ,0 ))
@@ -316,7 +316,7 @@ static int decode_int(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s" , level *TAB_SIZE ," " , f->name); +"%*s%s" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case BYTE :/* Range == 256 */
@@ -363,7 +363,7 @@ static int decode_int(struct bitstr *bs, const struct field_t *f,static int decode_enum (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);if ((f->attr &EXT ) &&get_bit (bs)) {INC_BITS (bs,7 );
@@ -381,7 +381,7 @@ static int decode_bitstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);BYTE_ALIGN (bs);switch (f->sz) {
@@ -417,7 +417,7 @@ static int decode_numstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* 2 <= Range <= 255 */ if (nf_h323_error_boundary (bs,0 , f->sz))
@@ -437,7 +437,7 @@ static int decode_octstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s" , level *TAB_SIZE ," " , f->name); +"%*s%s" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case FIXD :/* Range == 1 */
@@ -490,7 +490,7 @@ static int decode_bmpstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case BYTE :/* Range == 256 */
@@ -522,7 +522,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;
@@ -544,7 +544,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,/* Decode the root components */ for (i = opt =0 , son = f->fields; i < f->lb; i++, son++) {if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }
@@ -562,7 +562,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;
@@ -615,7 +615,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f, }if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }
@@ -629,7 +629,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;
@@ -655,7 +655,7 @@ static int decode_seqof(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;
@@ -710,7 +710,7 @@ static int decode_seqof(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;
@@ -751,7 +751,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;
@@ -792,7 +792,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,/* Transfer to son level */ son = &f->fields[type];if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }
@@ -804,7 +804,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;return H323_ERROR_NONE ;
Signature · 1 line
2.39.5
Pablo Neira Ayuso
maintainerHi David,
Quoted 9 lines · On Thu, Mar 26, 2026 at 08:18:19PM +0000, [email protected] wrote:
From: David Laight <[email protected]>
The trace lines are indented using
PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
Do you have a setup using this helper? Or you just found this via visual inspection?
Quoted 183 lines
Signed-off-by David Laight <[email protected]>--- net/netfilter/nf_conntrack_h323_asn1.c | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-)net/netfilter/nf_conntrack_h323_asn1.c +19
-19@@ -276,7 +276,7 @@ static unsigned int get_uint(struct bitstr *bs, int b)static int decode_nul (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);return H323_ERROR_NONE ; }@@ -284,7 +284,7 @@ static int decode_nul(struct bitstr *bs, const struct field_t *f,static int decode_bool (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);INC_BIT (bs);if (nf_h323_error_boundary (bs,0 ,0 ))@@ -297,7 +297,7 @@ static int decode_oid(struct bitstr *bs, const struct field_t *f, {int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);BYTE_ALIGN (bs);if (nf_h323_error_boundary (bs,1 ,0 ))@@ -316,7 +316,7 @@ static int decode_int(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s" , level *TAB_SIZE ," " , f->name); +"%*s%s" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case BYTE :/* Range == 256 */ @@ -363,7 +363,7 @@ static int decode_int(struct bitstr *bs, const struct field_t *f,static int decode_enum (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);if ((f->attr &EXT ) &&get_bit (bs)) {INC_BITS (bs,7 );@@ -381,7 +381,7 @@ static int decode_bitstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);BYTE_ALIGN (bs);switch (f->sz) {@@ -417,7 +417,7 @@ static int decode_numstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* 2 <= Range <= 255 */ if (nf_h323_error_boundary (bs,0 , f->sz))@@ -437,7 +437,7 @@ static int decode_octstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s" , level *TAB_SIZE ," " , f->name); +"%*s%s" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case FIXD :/* Range == 1 */ @@ -490,7 +490,7 @@ static int decode_bmpstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case BYTE :/* Range == 256 */ @@ -522,7 +522,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;@@ -544,7 +544,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,/* Decode the root components */ for (i = opt =0 , son = f->fields; i < f->lb; i++, son++) {if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }@@ -562,7 +562,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;@@ -615,7 +615,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f, }if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }@@ -629,7 +629,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;@@ -655,7 +655,7 @@ static int decode_seqof(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;@@ -710,7 +710,7 @@ static int decode_seqof(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;@@ -751,7 +751,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;@@ -792,7 +792,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,/* Transfer to son level */ son = &f->fields[type];if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }@@ -804,7 +804,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;return H323_ERROR_NONE ;Signature · 1 line
2.39.5
Quoted 10 lines · On Thu, 26 Mar 2026 21:24:39 +0100 Pablo Neira Ayuso <[email protected]>…
Hi David,
Quoted 7 lines · On Thu, Mar 26, 2026 at 08:18:19PM +0000, [email protected] wrote:
From: David Laight <[email protected]>
The trace lines are indented using
PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.
Quoted 5 lines
Quoted 2 lines
Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
Do you have a setup using this helper? Or you just found this via visual inspection?
Found with grep looking for places which might be affected by 'fixing' the kernel printf code to be POSIX compliant.
David
Quoted 184 lines
Quoted 184 lines
Signed-off-by David Laight <[email protected]>--- net/netfilter/nf_conntrack_h323_asn1.c | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-)net/netfilter/nf_conntrack_h323_asn1.c +19
-19@@ -276,7 +276,7 @@ static unsigned int get_uint(struct bitstr *bs, int b)static int decode_nul (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);return H323_ERROR_NONE ; }@@ -284,7 +284,7 @@ static int decode_nul(struct bitstr *bs, const struct field_t *f,static int decode_bool (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);INC_BIT (bs);if (nf_h323_error_boundary (bs,0 ,0 ))@@ -297,7 +297,7 @@ static int decode_oid(struct bitstr *bs, const struct field_t *f, {int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);BYTE_ALIGN (bs);if (nf_h323_error_boundary (bs,1 ,0 ))@@ -316,7 +316,7 @@ static int decode_int(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s" , level *TAB_SIZE ," " , f->name); +"%*s%s" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case BYTE :/* Range == 256 */ @@ -363,7 +363,7 @@ static int decode_int(struct bitstr *bs, const struct field_t *f,static int decode_enum (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);if ((f->attr &EXT ) &&get_bit (bs)) {INC_BITS (bs,7 );@@ -381,7 +381,7 @@ static int decode_bitstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);BYTE_ALIGN (bs);switch (f->sz) {@@ -417,7 +417,7 @@ static int decode_numstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* 2 <= Range <= 255 */ if (nf_h323_error_boundary (bs,0 , f->sz))@@ -437,7 +437,7 @@ static int decode_octstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s" , level *TAB_SIZE ," " , f->name); +"%*s%s" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case FIXD :/* Range == 1 */ @@ -490,7 +490,7 @@ static int decode_bmpstr(struct bitstr *bs, const struct field_t *f, {unsigned int len; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);switch (f->sz) {case BYTE :/* Range == 256 */ @@ -522,7 +522,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;@@ -544,7 +544,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,/* Decode the root components */ for (i = opt =0 , son = f->fields; i < f->lb; i++, son++) {if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }@@ -562,7 +562,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;@@ -615,7 +615,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f, }if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }@@ -629,7 +629,7 @@ static int decode_seq(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;@@ -655,7 +655,7 @@ static int decode_seqof(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;@@ -710,7 +710,7 @@ static int decode_seqof(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;continue ;@@ -751,7 +751,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,const struct field_t *son;unsigned char *beg =NULL ; -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);/* Decode? */ base = (base && (f->attr &DECODE )) ? base + f->offset :NULL ;@@ -792,7 +792,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,/* Transfer to son level */ son = &f->fields[type];if (son->attr &STOP ) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name);return H323_ERROR_STOP ; }@@ -804,7 +804,7 @@ static int decode_choice(struct bitstr *bs, const struct field_t *f,if (nf_h323_error_boundary (bs, len,0 ))return H323_ERROR_BOUND ;if (!base || !(son->attr &DECODE )) { -"%*.s%s\n" , (level +1 ) *TAB_SIZE ," " , +"%*s%s\n" , (level +1 ) *TAB_SIZE ," " , son->name); bs->cur += len;return H323_ERROR_NONE ;Signature · 1 line
2.39.5
Quoted 9 lines · David Laight
Quoted 7 lines · On Thu, 26 Mar 2026 21:24:39 +0100 Pablo Neira Ayuso <[email protected]>…
Quoted 6 lines · On Thu, Mar 26, 2026 at 08:18:19PM +0000, [email protected] wrote:
The trace lines are indented using
PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
Do you have a setup using this helper? Or you just found this via visual inspection?
Found with grep looking for places which might be affected by 'fixing' the kernel printf code to be POSIX compliant.
Do we have the respective test case in printf_kunit?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 13 lines · On Fri, 27 Mar 2026 11:24:50 +0200 Andy Shevchenko…
Quoted 12 lines · David Laight
Quoted 10 lines · On Thu, 26 Mar 2026 21:24:39 +0100 Pablo Neira Ayuso <[email protected]>…
Quoted 8 lines · On Thu, Mar 26, 2026 at 08:18:19PM +0000, [email protected] wrote:
The trace lines are indented using
PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do you have a setup using this helper? Or you just found this via visual inspection?
Found with grep looking for places which might be affected by 'fixing' the kernel printf code to be POSIX compliant.
Do we have the respective test case in
printf_kunit?
There are definitely related ones and this comment:
static voidtest_string(struct kunit *kunittest)
{
[...]
/*
* POSIX and C99 say that a negative precision (which is only
* possible to pass via a * argument) should be treated as if
* the precision wasn't present, and that if the precision is
* omitted (as in %.s), the precision should be taken to be
* 0. However, the kernel's printf behave exactly opposite,
* treating a negative precision as 0 and treating an omitted
* precision specifier as if no precision was given. *
* These test cases document the current behaviour; should
* anyone ever feel the need to follow the standards more
* closely, this can be revisited.
*/
test(" ", "%4.*s", -5, "123456");
[...]
}
I suspect whoever wrote the tests found the code was non-conformant. But there isn't a comment in the snprintf() code itself. I've not checked what the kernel code does (I've just written/fixed all this for nolibc - the kernel will fail the nolibc tests).
David
Quoted 20 lines · On Thu 2026-03-26 20:18:19, [email protected] wrote:
From: David Laight <[email protected]>
The trace lines are indented using
PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
Signed-off-by David Laight <[email protected]>--- net/netfilter/nf_conntrack_h323_asn1.c | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-)net/netfilter/nf_conntrack_h323_asn1.c +0
-0
net/netfilter/nf_conntrack_h323_asn1.c static unsigned int get_uint(struct bitstr *bs, int b) · line 282
Quoted 8 lines
net/netfilter/nf_conntrack_h323_asn1.c +1
-1@@ -276,7 +276,7 @@ static unsigned int get_uint(struct bitstr *bs, int b)static int decode_nul (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);return H323_ERROR_NONE ; }
The change is important for making the kernel %*.s handling POSIX compliant. The dot '.' without any following number is handled a zero precision by POSIX. It would print no space "" when also the field width was zero, aka when level == 0.
It has no efect if the field width (@level) is always > 0 because vsprintf() would add the required emptry spaces ' ' anyway.
Best Regards,
Petr
Quoted 35 lines · On Fri, 27 Mar 2026 10:47:41 +0100 Petr Mladek <[email protected]> wrote:
Quoted 20 lines · On Thu 2026-03-26 20:18:19, [email protected] wrote:
From: David Laight <[email protected]>
The trace lines are indented using
PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
Signed-off-by David Laight <[email protected]>--- net/netfilter/nf_conntrack_h323_asn1.c | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-)net/netfilter/nf_conntrack_h323_asn1.c +0
-0net/netfilter/nf_conntrack_h323_asn1.c static unsigned int get_uint(struct bitstr *bs, int b) · line 282
Quoted 8 lines
net/netfilter/nf_conntrack_h323_asn1.c +1
-1@@ -276,7 +276,7 @@ static unsigned int get_uint(struct bitstr *bs, int b)static int decode_nul (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);return H323_ERROR_NONE ; }The change is important for making the kernel %*.s handling POSIX compliant. The dot '.' without any following number is handled a zero precision by POSIX. It would print no space "" when also the field width was zero, aka when level == 0.
Quoted 2 lines
It has no efect if the field width (@level) is always > 0 because
vsprintf()would add the required emptry spaces ' ' anyway.
That looks like C&P AI output...
Quoted 7 lines
Reviewed-by Petr Mladek <[email protected]>Best Regards,
Petr
Quoted 38 lines · David Laight
Quoted 35 lines · On Fri, 27 Mar 2026 10:47:41 +0100 Petr Mladek <[email protected]> wrote:
Quoted 20 lines · On Thu 2026-03-26 20:18:19, [email protected] wrote:
From: David Laight <[email protected]>
The trace lines are indented using
PRINT("%*.s", xx, " "). Userspace will treat this as "%*.0s" and will output no characters when 'xx' is zero, the kernel treats it as "%*s" and will output a single ' ' - which is probably what is intended.Change all the formats to "%*s" removing the default precision. This gives a single space indent when level is zero.
Signed-off-by David Laight <[email protected]>--- net/netfilter/nf_conntrack_h323_asn1.c | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-)net/netfilter/nf_conntrack_h323_asn1.c +0
-0net/netfilter/nf_conntrack_h323_asn1.c static unsigned int get_uint(struct bitstr *bs, int b) · line 282
Quoted 8 lines
net/netfilter/nf_conntrack_h323_asn1.c +1
-1@@ -276,7 +276,7 @@ static unsigned int get_uint(struct bitstr *bs, int b)static int decode_nul (struct bitstr *bs,const struct field_t *f,char *base,int level) { -"%*.s%s\n" , level *TAB_SIZE ," " , f->name); +"%*s%s\n" , level *TAB_SIZE ," " , f->name);return H323_ERROR_NONE ; }The change is important for making the kernel %*.s handling POSIX compliant. The dot '.' without any following number is handled a zero precision by POSIX. It would print no space "" when also the field width was zero, aka when level == 0.
Quoted 4 lines
Quoted 2 lines
It has no efect if the field width (@level) is always > 0 because
vsprintf()would add the required emptry spaces ' ' anyway.That looks like C&P AI output...
I believe that these days AI would be able to formulate it a much better way than me.
Best Regards,
Petr