JSON scanf() function

#1

Hello.
I need transfer text type value from web page to RPC.
For test in RPC handler I try to use:

  char* message = NULL;
  if (json_scanf(args.p, args.len, ri->args_fmt, message))
  {
    LOG(LL_INFO, ("Message: %.s", message));
  }

But, I get an error:

[Jul 13 10:44:57.703] Guru Meditation Error: Core 1 panic’ed (StoreProhibited). Exception was unhandled.
[Jul 13 10:44:57.703]
[Jul 13 10:44:57.703] Core 1 register dump:
[Jul 13 10:44:57.703] PC : 0x4010afb2 PS : 0x00060430 A0 : 0x80105068 A1 : 0x3ffb5d90
[Jul 13 10:44:57.703] A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
[Jul 13 10:44:57.703] A6 : 0x00000001 A7 : 0x3ffb5d90 A8 : 0x00000000 A9 : 0x00000001
[Jul 13 10:44:57.703] A10 : 0x00000031 A11 : 0x3ffb61e0 A12 : 0x3ffb5f90 A13 : 0x00000004
[Jul 13 10:44:57.703] A14 : 0x00000068 A15 : 0x3ffb6120 SAR : 0x00000018 EXCCAUSE: 0x0000001d
[Jul 13 10:44:57.703] EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffd
[Jul 13 10:44:57.703]
[Jul 13 10:44:57.703] Backtrace:0x4010afaf 0x40105065 0x400d63e2 0x400d52e5 0x400d54b1 0x400d55a0 0x400d60b5 0x400d650e 0x400d65d9 0x400d65ff 0x400fe1d5 0x400fe432 0x40100a2d 0x401697cd 0x40169c35 0x40169ea6 0x401697cd 0x4016aac2 0x4016d508 0x4016d525 0x40175b0d 0x401658f1 0x400828bd 0x400827c5
[Jul 13 10:44:57.703]
[Jul 13 10:44:57.703]
[Jul 13 10:44:57.703] ELF file SHA256: 0e6532941146acd5
[Jul 13 10:44:57.703]
[Jul 13 10:44:57.703]
[Jul 13 10:44:57.703] — BEGIN CORE DUMP —
[Jul 13 10:44:57.703] mos: catching core dump

I think, it’s because of char* message = NULL; variable message hasn’t fixed length.
But using of fixed leangth variable doesn’t suit me, because message can be of any length.
How can I solve the problem??

#2
json_scanf(args.p, args.len, ri->args_fmt, message)

should read

json_scanf(args.p, args.len, ri->args_fmt, &message)

provided args_fmt is something like "{msg:%Q}".

Ref

1 Like