Git Product home page Git Product logo

Comments (7)

r00t- avatar r00t- commented on August 22, 2024

with current volkszaehler/libsml master:

[/tmp/libsml]$ gdb ./examples/sml_server
Reading symbols from ./examples/sml_server...done.
(gdb) run - <EMH_eHZ-IW8E2A5L0EK2P_crash.bin 
Starting program: /tmp/libsml/examples/sml_server - <EMH_eHZ-IW8E2A5L0EK2P_crash.bin
SML file (3 SML messages, 344 bytes)
SML message  101
SML message  701
SML message  201
OBIS data
libsml: error: unknown type 0 in sml_value_to_double
libsml: error: unknown type 0 in sml_value_to_double
1-0:1.8.0*255#2795692.7#Wh
1-0:1.8.1*255#2795692.7#Wh
1-0:16.7.0*255#136.7#W
libsml: error: unknown type 0 in sml_value_to_double

Program received signal SIGSEGV, Segmentation fault.
0x0000000000401153 in transport_receiver (buffer=0x7fffffffc430 "\033\033\033\033\001\001\001\001v\a", buffer_len=360)
    at sml_server.c:104
104                                             switch (*entry->unit) {
(gdb) p *entry
$1 = {obj_name = 0x60cd80, status = 0x0, val_time = 0x0, unit = 0x0, scaler = 0x0, value = 0x60cdc0, value_signature = 0x0, next = 0x60ce00}
(gdb) 

from libsml.

r00t- avatar r00t- commented on August 22, 2024
 44 typedef struct sml_list_entry {
 45     octet_string *obj_name;
 46     sml_status *status; // optional
 47     sml_time *val_time; // optional
 48     sml_unit *unit; // optional

this seems to indicate this first bug is in sml_server.c, relying on an optional field being present.

but there's more after that...

from libsml.

r00t- avatar r00t- commented on August 22, 2024
Program received signal SIGSEGV, Segmentation fault.
0x0000000000402f4a in sml_value_to_double (value=0x0) at src/sml_value.c:113
113             switch (value->type) {

downright silly, the parser returns an entry with a null value and we pass that to _to_double...

i do not know if it's sensible for the parser to return such an entry.

from libsml.

r00t- avatar r00t- commented on August 22, 2024

after fixing those two (both in sml_server.c), no more crashing.
(instead the program hangs because it ignores EOF)

from libsml.

r00t- avatar r00t- commented on August 22, 2024

does not seem worth forking the repo for this:

[/tmp/libsml]$ git diff
diff --git a/examples/sml_server.c b/examples/sml_server.c
index df29996..bbaabdd 100644
--- a/examples/sml_server.c
+++ b/examples/sml_server.c
@@ -37,6 +37,8 @@ int serial_port_open(const char* device) {
        struct termios config;
        memset(&config, 0, sizeof(config));
 
+    if (!strcmp(device,"-")) return 0; // read stdin when "-" is given for the device
+
 #ifdef O_NONBLOCK
        int fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
 #else
@@ -90,6 +92,7 @@ void transport_receiver(unsigned char *buffer, size_t buffer_len) {
                        sml_get_list_response *body;
                        body = (sml_get_list_response *) message->message_body->data;
                        for (entry = body->val_list; entry != NULL; entry = entry->next) {
+                               if (!entry->value) continue; // do not crash on null entries
                                value = sml_value_to_double(entry->value);
                                if (value != 0) {
                                        int scaler = (entry->scaler) ? *entry->scaler : 1;
@@ -99,7 +102,7 @@ void transport_receiver(unsigned char *buffer, size_t buffer_len) {
                                                entry->obj_name->str[0], entry->obj_name->str[1],
                                                entry->obj_name->str[2], entry->obj_name->str[3],
                                                entry->obj_name->str[4], entry->obj_name->str[5], value);
-                                       switch (*entry->unit) {
+                                       if (entry->unit) switch (*entry->unit) {
                                        case 0x1B:
                                                printf("W");
                                                break;
@@ -129,15 +132,15 @@ int main(int argc, char *argv[]) {
        }
 
        // check for serial port
-       if (access(argv[1], F_OK) == -1) {
+       if (strcmp(argv[1],"-")&&access(argv[1], F_OK) == -1) {
                printf("Error: no such device (%s)\n", argv[1]);
                exit(2);
        }
 
        // open serial port
        int fd = serial_port_open(argv[1]);
-       if (!fd) {
-               printf("Error: can''t open device (%s)\n", argv[1]);
+       if (fd<0) {
+               printf("Error: can't open device (%s)\n", argv[1]);
                exit(3);
        }
 

from libsml.

r00t- avatar r00t- commented on August 22, 2024

here is a PR after all: #34

from libsml.

r00t- avatar r00t- commented on August 22, 2024

i would say the libsml code is pretty stable otherwise:

[/tmp/libsml]$ bfr -p </dev/urandom | ./examples/sml_server -
[ ######################################## ][ 760.7k/s->5088.0k->757.6k/s (142292.0k) ]

(we might want to create an input with more valid sml frame headers)

from libsml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.