I was trying to do a cfg_rpc update on a variable and some of the times, the variable would take on randomly large values or negative values.
The -1 here is probably causing issues.
https://github.com/kamailio/kamailio/blob/1d53ea3dba4e59b05b2e92ecc973c4415…
Here's an explanation of what's going on (debugged using gdb). In cfg_struc.c if you put a breakpoint in the following line in cfg_clone_global
https://github.com/kamailio/kamailio/blob/1d53ea3dba4e59b05b2e92ecc973c4415…
checking variable values:
```
--- Old (correct) value ---
(gdb) print sizeof(*(int *)(((unsigned char *)((*cfg_global)->vars + 984)) + 172))
$33 = 4
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((*cfg_global)->vars + 984)) + 172)) + 0)
$34 = 99 'c'
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((*cfg_global)->vars + 984)) + 172)) + 1)
$35 = 0 '\000'
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((*cfg_global)->vars + 984)) + 172)) + 2)
$36 = 0 '\000'
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((*cfg_global)->vars + 984)) + 172)) + 3)
$37 = 0 '\000'
--- new (corrupt) value ---
(gdb) print sizeof(*(int *)(((unsigned char *)((block)->vars + 984)) + 172))
$28 = 4
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((block)->vars + 984)) + 172)) + 0)
$29 = 99 'c'
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((block)->vars + 984)) + 172)) + 1)
$30 = 0 '\000'
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((block)->vars + 984)) + 172)) + 2)
$31 = 0 '\000'
(gdb) print *((unsigned char *)&(*(int *)(((unsigned char *)((block)->vars + 984)) + 172)) + 3)
$32 = 130 '\202'
```
As visible, the last byte is getting corrupted.
I checked the memory allocation variables:
```
--> cfg_block_size
(gdb) print cfg_block_size
$2 = 1156
--> sizeof(cfg_block_t)
print sizeof(cfg_block_t)
$15 = 8
```
This means that total memory assigned = 8 + 1156 -(1) = 1163
```
--> address of new block
(gdb) print (void *) block
$12 = (void *) 0x7f63086b6758
--> address of the corrupted variable in the new block
(gdb) print (void *)(((unsigned char *)((block)->vars + 984)) + 172)
$13 = (void *) 0x7f63086b6be0
--> offset of the variable from the block start
(gdb) print 0x7f63086b6be0 - 0x7f63086b6758
$14 = 1160
```
since the variable is an integer, memory that should be assigned = 1160 + 4 = 1164
However, we're assigning 1163.
Therefore the last byte is getting corrupted.
Does it make sense to remove the -1 from all the memory allocation in cfg_struct ?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1583
Hello,
kamcli tool just got its first official release, a step forward in the
process of packaging it.
It is a command line tool that aims to be a modern alternative to the
venerable kamctl, being written in Python and having already a large set
of implemented sub-commands, such as:
* subscriber – manage SIP subscribers
* ul – manage user location records
* address – manage permissions address records
* aliasdb – manage database aliases
* db – manage kamailio database content
* dialog – manage active calls (dialog)
* dialplan – manage dialplan records
* dispatcher – manage load balancer (dispatcher)
* group – manage group membership records (acl)
* moni – continuous refresh of the values for a list of statistics
* mtree – manage memory trees (mtree)
* ps – print the details for kamailio running processes
* rpc – interact with kamailio via jsonrpc control commands (alias of
jsonrpc)
* rpcmethods – return the list of available RPC methods (commands)
* speeddial – manage speed dial records
* srv – server management commands (sockets, aliases, …)
* stats – get kamailio internal statistics
* tls – management commands for TLS profiles and connections
* uptime – print the uptime for kamailio instance
The news article for this release is available at:
* https://www.kamailio.org/w/2018/10/kamcli-v1-1-0-released/
The corresponding tag in the github repository being:
* https://github.com/kamailio/kamcli/releases/tag/v1.1.0
How to install kamcli and examples of usage can be found at:
* https://github.com/kamailio/kamcli/blob/v1.1/README.md
Cheers,
Daniel
--
Daniel-Constantin Mierla -- www.asipto.comwww.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio World Conference -- www.kamailioworld.com
Kamailio Advanced Training, Nov 12-14, 2018, in Berlin -- www.asipto.com