fix segfault on x32, 64-bit time_t-related format strings
PATCH 1/1 fix segfault on x32, 64-bit time_t-related format strings
Hi everyone,
here are two patches I’ve been rebasing with each new upload of alsa-lib to Debian to make things work for my x32 desktop.
The small one fixes it misdetecting x32 as amd64, which leads to an immediate segfault.
The other one fixes issues related to printing time_t values on platforms where time_t is 64 bit wide and long 32 bit wide (various BSDs and all new 32-bit and *64ilp32 Linux platforms).
The Debian packager of alsa-lib hasn’t found it necessary to forward them upstream, so I’m doing it with this. I hope they can be included in the next releases. The patches were last updated for 1.1.8 although I need to update them to 1.1.9 which was recently introduced to Debian… usually they apply still.
Thanks in advance,
//mirabilos
Signature · 14 lines
tarent solutions GmbH Rochusstraße 2-4, D-53123 Bonn • http://www.tarent.de/ Tel: +49 228 54881-393 • Fax: +49 228 54881-235 HRB 5168 (AG Bonn) • USt-ID (VAT): DE122264941 Geschäftsführer: Dr. Stefan Barth, Kai Ebenrett, Boris Esser, Alexander Steeg ********** Mit der tarent Academy bieten wir auch Trainings und Schulungen in den Bereichen Softwareentwicklung, Agiles Arbeiten und Zukunftstechnologien an. Besuchen Sie uns auf www.tarent.de/academy. Wir freuen uns auf Ihren Kontakt. **********
# DP: fix long vs. long long confusion when there is a 64-bit time_t # DP: on a 32-bit long system, such as all newer 32-bit architectures
src/pcm/pcm.c +5 -5
@@ -2257,11 +2257,11 @@ int snd_pcm_status_dump(snd_pcm_status_t {assert (status);snd_output_printf (out," state : %s\n" ,snd_pcm_state_name ((snd_pcm_state_t ) status->state)); -snd_output_printf (out," trigger_time: %ld.%06ld\n" , - status->trigger_tstamp.tv_sec, - status->trigger_tstamp.tv_nsec /1000 ); -snd_output_printf (out," tstamp : %ld.%06ld\n" , - status->tstamp.tv_sec, status->tstamp.tv_nsec /1000 ); +snd_output_printf (out," trigger_time: %lld.%06ld\n" , + (long long )status->trigger_tstamp.tv_sec, + (long )status->trigger_tstamp.tv_nsec /1000L ); +snd_output_printf (out," tstamp : %lld.%06ld\n" , + (long long )status->tstamp.tv_sec, (long )status->tstamp.tv_nsec /1000L );snd_output_printf (out," delay : %ld\n" , (long )status->delay);snd_output_printf (out," avail : %ld\n" , (long )status->avail);snd_output_printf (out," avail_max : %ld\n" , (long )status->avail_max);
test/latency.c +6 -6
@@ -325,12 +325,12 @@ void setscheduler(void)printf ("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n" , sched_param.sched_priority); } -long timediff (snd_timestamp_t t1,snd_timestamp_t t2) +long long timediff (snd_timestamp_t t1,snd_timestamp_t t2) { -signed long l; +signed long long l; t1.tv_sec -= t2.tv_sec; - l = (signed long ) t1.tv_usec - (signed long ) t2.tv_usec; + l = (signed long long ) t1.tv_usec - (signed long long ) t2.tv_usec;if (l <0 ) { t1.tv_sec--; l =1000000 + l;
@@ -682,10 +682,10 @@ int main(int argc, char *argv[])snd_pcm_nonblock (phandle, !block ?1 :0 );if (ok) {#if 1 -printf ("Playback time = %li.%i, Record time = %li.%i, diff = %li\n" , - p_tstamp.tv_sec, +printf ("Playback time = %lli.%i, Record time = %lli.%i, diff = %lli\n" , + (long long )p_tstamp.tv_sec, (int )p_tstamp.tv_usec, - c_tstamp.tv_sec, + (long long )c_tstamp.tv_sec, (int )c_tstamp.tv_usec,timediff (p_tstamp, c_tstamp));#endif
test/queue_timer.c +5 -5
@@ -99,11 +99,11 @@ main(int argc ATTRIBUTE_UNUSED, char **anormalize (&diffdiff); prevdiff = diff; -fprintf (stderr," real time: %12ld sec %8ld usec\nqueue time: %12ld sec %8ld usec\n diff: %12ld sec %8ld usec\n diffdiff: %12ld sec %8ld usec\n" , - tv.tv_sec, tv.tv_usec, - (long )rtime->tv_sec, (long )rtime->tv_nsec /1000 , - diff.tv_sec, diff.tv_usec, - (long )diffdiff.tv_sec, (long )diffdiff.tv_usec); +fprintf (stderr," real time: %12lld sec %8ld usec\nqueue time: %12lld sec %8ld usec\n diff: %12lld sec %8ld usec\n diffdiff: %12lld sec %8ld usec\n" , + (long long )tv.tv_sec, (long )tv.tv_usec, + (long long )rtime->tv_sec, (long )rtime->tv_nsec /1000 , + (long long )diff.tv_sec, (long )diff.tv_usec, + (long long )diffdiff.tv_sec, (long )diffdiff.tv_usec);if (diffdiff.tv_usec >5000 || diffdiff.tv_usec <-5000 ) {
# DP: fix segmentation fault coming from this using amd64 assembly code # DP: on x32 systems
src/pcm/pcm_dmix.c +1 -1
@@ -145,7 +145,7 @@ static void dmix_server_free(snd_pcm_dir#include "pcm_dmix_generic.c" #if defined(__i386__)#include "pcm_dmix_i386.c" -#elif defined(__x86_64__) +#elif defined(__x86_64__) && !defined(__ILP32__)#include "pcm_dmix_x86_64.c" #else #ifndef DOC_HIDDEN
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 13 lines · Thorsten Glaser
Hi everyone,
here are two patches I’ve been rebasing with each new upload of alsa-lib to Debian to make things work for my x32 desktop.
The small one fixes it misdetecting x32 as amd64, which leads to an immediate segfault.
The other one fixes issues related to printing
time_tvalues on platforms wheretime_tis 64 bit wide and long 32 bit wide (various BSDs and all new 32-bit and *64ilp32 Linux platforms).
Quoted 5 lines
The Debian packager of alsa-lib hasn’t found it necessary to forward them upstream, so I’m doing it with this. I hope they can be included in the next releases. The patches were last updated for 1.1.8 although I need to update them to 1.1.9 which was recently introduced to Debian… usually they apply still.
Could you split these changes to separate patches? They are for different purposes.
Also, using time_t would be better if possible. Unfortunately a cast is needed for printf usage, but other than that, time_t would leave us the right size.
thanks,
Takashi
Quoted 105 lines
Thanks in advance,
//mirabilosSignature · 16 lines
tarent solutions GmbH Rochusstraße 2-4, D-53123 Bonn • http://www.tarent.de/ Tel: +49 228 54881-393 • Fax: +49 228 54881-235 HRB 5168 (AG Bonn) • USt-ID (VAT): DE122264941 Geschäftsführer: Dr. Stefan Barth, Kai Ebenrett, Boris Esser, Alexander Steeg ********** Mit der tarent Academy bieten wir auch Trainings und Schulungen in den Bereichen Softwareentwicklung, Agiles Arbeiten und Zukunftstechnologien an. Besuchen Sie uns auf www.tarent.de/academy. Wir freuen uns auf Ihren Kontakt. ********** # DP: fix long vs. long long confusion when there is a 64-bit time_t # DP: on a 32-bit long system, such as all newer 32-bit architecturessrc/pcm/pcm.c +5
-5@@ -2257,11 +2257,11 @@ int snd_pcm_status_dump(snd_pcm_status_t {assert (status);snd_output_printf (out," state : %s\n" ,snd_pcm_state_name ((snd_pcm_state_t ) status->state)); -snd_output_printf (out," trigger_time: %ld.%06ld\n" , - status->trigger_tstamp.tv_sec, - status->trigger_tstamp.tv_nsec /1000 ); -snd_output_printf (out," tstamp : %ld.%06ld\n" , - status->tstamp.tv_sec, status->tstamp.tv_nsec /1000 ); +snd_output_printf (out," trigger_time: %lld.%06ld\n" , + (long long )status->trigger_tstamp.tv_sec, + (long )status->trigger_tstamp.tv_nsec /1000L ); +snd_output_printf (out," tstamp : %lld.%06ld\n" , + (long long )status->tstamp.tv_sec, (long )status->tstamp.tv_nsec /1000L );snd_output_printf (out," delay : %ld\n" , (long )status->delay);snd_output_printf (out," avail : %ld\n" , (long )status->avail);snd_output_printf (out," avail_max : %ld\n" , (long )status->avail_max);test/latency.c +6
-6@@ -325,12 +325,12 @@ void setscheduler(void)printf ("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n" , sched_param.sched_priority); } -long timediff (snd_timestamp_t t1,snd_timestamp_t t2) +long long timediff (snd_timestamp_t t1,snd_timestamp_t t2) { -signed long l; +signed long long l; t1.tv_sec -= t2.tv_sec; - l = (signed long ) t1.tv_usec - (signed long ) t2.tv_usec; + l = (signed long long ) t1.tv_usec - (signed long long ) t2.tv_usec;if (l <0 ) { t1.tv_sec--; l =1000000 + l;@@ -682,10 +682,10 @@ int main(int argc, char *argv[])snd_pcm_nonblock (phandle, !block ?1 :0 );if (ok) {#if 1 -printf ("Playback time = %li.%i, Record time = %li.%i, diff = %li\n" , - p_tstamp.tv_sec, +printf ("Playback time = %lli.%i, Record time = %lli.%i, diff = %lli\n" , + (long long )p_tstamp.tv_sec, (int )p_tstamp.tv_usec, - c_tstamp.tv_sec, + (long long )c_tstamp.tv_sec, (int )c_tstamp.tv_usec,timediff (p_tstamp, c_tstamp));#endif test/queue_timer.c +5
-5@@ -99,11 +99,11 @@ main(int argc ATTRIBUTE_UNUSED, char **anormalize (&diffdiff); prevdiff = diff; -fprintf (stderr," real time: %12ld sec %8ld usec\nqueue time: %12ld sec %8ld usec\n diff: %12ld sec %8ld usec\n diffdiff: %12ld sec %8ld usec\n" , - tv.tv_sec, tv.tv_usec, - (long )rtime->tv_sec, (long )rtime->tv_nsec /1000 , - diff.tv_sec, diff.tv_usec, - (long )diffdiff.tv_sec, (long )diffdiff.tv_usec); +fprintf (stderr," real time: %12lld sec %8ld usec\nqueue time: %12lld sec %8ld usec\n diff: %12lld sec %8ld usec\n diffdiff: %12lld sec %8ld usec\n" , + (long long )tv.tv_sec, (long )tv.tv_usec, + (long long )rtime->tv_sec, (long )rtime->tv_nsec /1000 , + (long long )diff.tv_sec, (long )diff.tv_usec, + (long long )diffdiff.tv_sec, (long )diffdiff.tv_usec);if (diffdiff.tv_usec >5000 || diffdiff.tv_usec <-5000 ) {# DP: fix segmentation fault coming from this using amd64 assembly code # DP: on x32 systems
src/pcm/pcm_dmix.c +1
-1@@ -145,7 +145,7 @@ static void dmix_server_free(snd_pcm_dir#include "pcm_dmix_generic.c" #if defined(__i386__)#include "pcm_dmix_i386.c" -#elif defined(__x86_64__) +#elif defined(__x86_64__) && !defined(__ILP32__)#include "pcm_dmix_x86_64.c" #else #ifndef DOC_HIDDEN
Quoted 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 2 lines · Takashi Iwai
Could you split these changes to separate patches? They are for different purposes.
I’ve sent them as two separate patch files attachments.
Quoted 3 lines
Also, using
time_twould be better if possible. Unfortunately a cast is needed for printf usage, but other than that,time_twould leave us the right size.
In timediff() you mean? Hrm, indeed. I tried to be minimal-invasive at first.
bye,
//mirabilos
Signature · 9 lines
tarent solutions GmbH Rochusstraße 2-4, D-53123 Bonn • http://www.tarent.de/ Tel: +49 228 54881-393 • Fax: +49 228 54881-235 HRB 5168 (AG Bonn) • USt-ID (VAT): DE122264941 Geschäftsführer: Dr. Stefan Barth, Kai Ebenrett, Boris Esser, Alexander Steeg _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 7 lines · Thorsten Glaser
Quoted 2 lines · Takashi Iwai
Could you split these changes to separate patches? They are for different purposes.
I’ve sent them as two separate patch files attachments.
Then please make them cleanly applicable via git-am, with a proper subject, a proper changelog and your sign-off, etc.
At best send one patch per mail (and with a cover letter for multiple patches).
Quoted 6 lines
Quoted 3 lines
Also, using
time_twould be better if possible. Unfortunately a cast is needed for printf usage, but other than that,time_twould leave us the right size.In
timediff()you mean? Hrm, indeed. I tried to be minimal-invasive at first.
I meant using time_t as much as possible instead of long long. For printf(), there is no other option, but other calculations can be replaced with time_t.
thanks,
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 4 lines · Takashi Iwai
Quoted 1 line
I’ve sent them as two separate patch files attachments.
Then please make them cleanly applicable via git-am, with a proper subject, a proper changelog and your sign-off, etc.
I’ll resend them like that now. Sorry it took a bit, I was busy.
Quoted 2 lines
At best send one patch per mail (and with a cover letter for multiple patches).
This is a bit tricky, as I can’t easily inject git format-patch output into this mail setup. I will try sending them from home.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Also, using
time_twould be better if possible. Unfortunately a cast is needed for printf usage, but other than that,time_twould leave us the right size.In
timediff()you mean? Hrm, indeed. I tried to be minimal-invasive at first.I meant using
time_tas much as possible instead of long long.
I’ve done this now.
bye,
//mirabilos
Signature · 9 lines
tarent solutions GmbH Rochusstraße 2-4, D-53123 Bonn • http://www.tarent.de/ Tel: +49 228 54881-393 • Fax: +49 228 54881-235 HRB 5168 (AG Bonn) • USt-ID (VAT): DE122264941 Geschäftsführer: Dr. Stefan Barth, Kai Ebenrett, Boris Esser, Alexander Steeg _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 1/3 pcm: ensure amd64-specific asm code is not used on x32
This fixes segfaults on x32 systems.
--- src/pcm/pcm_dmix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/pcm/pcm_dmix.c +1 -1
@@ -142,7 +142,7 @@ static void dmix_server_free(snd_pcm_direct_t *dmix)#include "pcm_dmix_generic.c" #if defined(__i386__)#include "pcm_dmix_i386.c" -#elif defined(__x86_64__) +#elif defined(__x86_64__) && !defined(__ILP32__)#include "pcm_dmix_x86_64.c" #else #ifndef DOC_HIDDEN
Signature · 6 lines
2.25.0 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 2/3 pcm: explicitly cast time types to types printf can handle
In reply to Thorsten Glaser--- src/pcm/pcm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
src/pcm/pcm.c +5 -5
@@ -2329,11 +2329,11 @@ int snd_pcm_status_dump(snd_pcm_status_t *status, snd_output_t *out) {assert (status);snd_output_printf (out," state : %s\n" ,snd_pcm_state_name ((snd_pcm_state_t ) status->state)); -snd_output_printf (out," trigger_time: %ld.%06ld\n" , - status->trigger_tstamp.tv_sec, - status->trigger_tstamp.tv_nsec /1000 ); -snd_output_printf (out," tstamp : %ld.%06ld\n" , - status->tstamp.tv_sec, status->tstamp.tv_nsec /1000 ); +snd_output_printf (out," trigger_time: %lld.%06ld\n" , + (long long )status->trigger_tstamp.tv_sec, + (long )status->trigger_tstamp.tv_nsec /1000L ); +snd_output_printf (out," tstamp : %lld.%06ld\n" , + (long long )status->tstamp.tv_sec, (long )status->tstamp.tv_nsec /1000L );snd_output_printf (out," delay : %ld\n" , (long )status->delay);snd_output_printf (out," avail : %ld\n" , (long )status->avail);snd_output_printf (out," avail_max : %ld\n" , (long )status->avail_max);
Signature · 6 lines
2.25.0 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 3/3 test: explicitly cast time types to types printf can handle
In reply to Thorsten GlaserAlso (as requested by Takashi Iwai), convert timediff() to time_t, as it’s the proper return type.
--- test/latency.c | 10 +++++----- test/queue_timer.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-)
test/latency.c +5 -5
@@ -325,7 +325,7 @@ void setscheduler(void)printf ("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n" , sched_param.sched_priority); } -long timediff (snd_timestamp_t t1,snd_timestamp_t t2) +time_t timediff (snd_timestamp_t t1,snd_timestamp_t t2) {signed long l;
@@ -683,12 +683,12 @@ int main(int argc, char *argv[])snd_pcm_nonblock (phandle, !block ?1 :0 );if (ok) {#if 1 -printf ("Playback time = %li.%i, Record time = %li.%i, diff = %li\n" , - p_tstamp.tv_sec, +printf ("Playback time = %lli.%i, Record time = %lli.%i, diff = %lli\n" , + (long long )p_tstamp.tv_sec, (int )p_tstamp.tv_usec, - c_tstamp.tv_sec, + (long long )c_tstamp.tv_sec, (int )c_tstamp.tv_usec, -timediff (p_tstamp, c_tstamp)); + (long long )timediff (p_tstamp, c_tstamp));#endif break ; }
test/queue_timer.c +5 -5
@@ -99,11 +99,11 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)normalize (&diffdiff); prevdiff = diff; -fprintf (stderr," real time: %12ld sec %8ld usec\nqueue time: %12ld sec %8ld usec\n diff: %12ld sec %8ld usec\n diffdiff: %12ld sec %8ld usec\n" , - tv.tv_sec, tv.tv_usec, - (long )rtime->tv_sec, (long )rtime->tv_nsec /1000 , - diff.tv_sec, diff.tv_usec, - (long )diffdiff.tv_sec, (long )diffdiff.tv_usec); +fprintf (stderr," real time: %12lld sec %8ld usec\nqueue time: %12lld sec %8ld usec\n diff: %12lld sec %8ld usec\n diffdiff: %12lld sec %8ld usec\n" , + (long long )tv.tv_sec, (long )tv.tv_usec, + (long long )rtime->tv_sec, (long )rtime->tv_nsec /1000 , + (long long )diff.tv_sec, (long )diff.tv_usec, + (long long )diffdiff.tv_sec, (long )diffdiff.tv_usec);if (diffdiff.tv_usec >5000 || diffdiff.tv_usec <-5000 ) {
Signature · 6 lines
2.25.0 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel