damian-m-g / xlsx_drone

Fast Microsoft Excel's *.xlsx reader
MIT License
13 stars 3 forks source link

missing ENVIRONMENT_VARIABLE_TEMP #3

Closed tfarina closed 2 years ago

tfarina commented 2 years ago

Program received signal SIGSEGV, Segmentation fault. __strlen_sse2_bsf () at ../sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S:50 50 ../sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S: No such file or directory. (gdb) p temp_path No symbol "temp_path" in current context. (gdb) p temp_folder No symbol "temp_folder" in current context. (gdb) up

1 0x0804b3ec in xlsx_open (src=0x8069b08 "test.xlsx", xlsx=0xbfffeea4) at ../third_party/xlsx_drone/xlsx_drone.c:54

54 int deployed_xlsx_path_len = strlen(temp_path) + strlen(temp_folder); (gdb) p temp_folder $1 = 0xb7fb580c "/tmp/fileDVib7r" (gdb) p temp_path $2 = 0x0

I don't have this variable in my environment.

damian-m-g commented 2 years ago

Hi, can you tell me what OS are you running?

tfarina commented 2 years ago

Ubuntu/Linux 16.04

damian-m-g commented 2 years ago

Hello, please check how it goes with the current version of the files (commit https://github.com/damian-m-g/xlsx_drone/commit/de769ec4895e092f3a6b770cb4880d6cbe00e2c2). Should also fix #2 .

tfarina commented 2 years ago

Fixed for me.

I had to include errno.h to fix the only error remaining:

In file included from ../xlsx_drone.c:3:0: ../xlsx_drone.c: In function ‘delete_folder’: ../xlsx_drone.h:37:29: error: ‘errno’ undeclared (first use in this function)

define XLSX_SET_ERRNO(x) errno=(x)

                         ^

../xlsx_drone.c:1057:3: note: in expansion of macro ‘XLSX_SET_ERRNO’ XLSX_SET_ERRNO(0); ^ ../xlsx_drone.h:37:29: note: each undeclared identifier is reported only once for each function it appears in

define XLSX_SET_ERRNO(x) errno=(x)

                         ^

../xlsx_drone.c:1057:3: note: in expansion of macro ‘XLSX_SET_ERRNO’ XLSX_SET_ERRNO(0);

damian-m-g commented 2 years ago

Okay. Last problem should be fixed with last commit (https://github.com/damian-m-g/xlsx_drone/commit/6428b355e16b77569bfe365f698cece98d181ef7), I've posted a release for this new version, 0.2.2. In case it doesn't work, please let me know.

Thanks for reporting the issues :)

tfarina commented 2 years ago

This might be a bug in my system, but I don't have any of the following variables defined: TMPDIR, TEMP, TMP.

So the call getenv(ENVIRONMENT_VARIABLE_TEMP); ends up returning NULL, and when it calls strlen(temp_path), it raises a Segmentation fault.

You might want to look at https://github.com/stephenmathieson/tempdir.c/blob/master/tempdir.c for a more complex solution. This returns /tmp, because I have this directory on my system.

damian-m-g commented 2 years ago

Hi @tfarina, I've implemented a simple fix. As far as I understand, it's rare to not have those env variables defined, but in that case POSIX/FHS says that "/tmp" is the root for temporary files so I'm hardcoding that in case those env vars aren't defined. Commit https://github.com/damian-m-g/xlsx_drone/commit/16693c84b52a882b89513c61a7e04da7ecf1f907 does it, and also the last release (0.2.3). Thanks for the tips on how to handle the temp dir issue, I've made a copy of that snippet for future needs. Cheers.

tfarina commented 2 years ago

Thanks, it has fixed this issue.